Voat->Gvid archive

4/21/2022, 9:17:28 PM

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Voat->Gvid archive
// @namespace   Violentmonkey Scripts
// @match       *://www.voat.xyz/*
// @match       *://www.talk.lol/*
// @grant       none
// @version     1.0
// @author      -
// @description 4/21/2022, 9:17:28 PM
// @require https://cdnjs.cloudflare.com/ajax/libs/js-sha1/0.6.0/sha1.min.js
// @license MIT
// ==/UserScript==
/* jshint esversion: 6 */
const user='';
const key='';  //Get a key at https://gvid.tv/manage
const buttontext='Archive on Gvid'

var extensions = new Set(['webm','mp4']);

function sha1hash(string) {
 var hash=sha1.create();
 hash.update(string);
 hash.update(key);
 hash.digest();
 return hash.hex();
}

function sendsecure(action,parameters,cb) {
 var innerobj={user,action,parameters,time:Date.now()};
 var innerjson=JSON.stringify(innerobj);
 var outerobj={payload:innerjson,hmac:sha1hash(innerjson)};
 fetch('https://gvid.tv/userapi',{
  method:'POST',
  body:JSON.stringify(outerobj)
 }).then(resp=>cb(null,resp)).catch(cb);
}

function buttonclick(e) {
 var b = e.target;
 var post = b.closest('.post-container,.post-container2');
 var url=posturl(post);
 var title=posttitle(post);
 var postid=post.id.replace('post_','');
 var host=location.host.indexOf('voat.xyz')!=-1?'voat.xyz':'talk.lol'; //Also gets rid of www
 var hostname=host=='voat.xyz'?'Voat':'Talk.lol'; //Display version
 var commentsurl=`https://${host}/viewpost?postid=${postid}`;
 var description=`[Discussion on ${hostname}](${commentsurl})`; //Markdown
 sendsecure('directupload',{title,url,description},(err,resp)=>{
  if(err) return alert(err);
  b.remove(); 
 });
}

function testurl(url) {
 var extension=url.split('.').pop().toLowerCase();
 if(extensions.has(extension)) return true;
 return false;
}

function posturl(post) {
 return post.querySelector('a').href;
}
function posttitle(post) {
 return post.querySelector('.post-title a').innerText;
}

function testpost(post) {
 return testurl(posturl(post));
}

function postlist() {
 return document.querySelectorAll('.post-container,.post-container2');
}

function targetposts() {
 return Array.prototype.filter.apply(postlist(),[testpost]);
}

function addbuttontopost(post) {
 var button=document.createElement('button');
 button.innerText=buttontext;
 button.addEventListener('click',buttonclick);
 post.querySelector('.post-title').append(button);
 button.style="cursor:pointer;";
}

function addbuttons() {
 targetposts().forEach(addbuttontopost);
}

addbuttons();