Provides link suggestions based on the current page, similar to youtube
目前為
// ==UserScript==
// @name Sugg
// @namespace Sugg Systems
// @description Provides link suggestions based on the current page, similar to youtube
// @match *://*/*
// @grant GM_setValue
// @grant GM_getValue
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @version 0.0.1.20190228140853
// ==/UserScript==
function suggdiv() {
var div = $('<body>');
div.css('min-height','100%');
div.css('width','25%');
div.css('display','flex');
div.css('flex-flow','column');
return div;
}
function suggmagic(history,url,title,cb) {
$.post('https://sugg.lifelist.pw/',JSON.stringify({history,url,title}),rank=>{
cb(null,rank);
}).fail(err=>{
cb(err);
});
}
function rankitem2div(item) {
var div = $('<div>').css('padding','8px');
var a = $('<a>').attr('href',item.href).text(item.title||item.href);
div.append(a);
return div;
}
function testOmit(url) {
if(url.match(/google.com\/recaptcha/)) {
return true;
}
if(url.match(/imgoat.com\/uploads/)) {
return true;
}
if(url.match(/phuks.co\/submit/)) {
return true;
}
if(url.match(/\/sign_in/)) {
return true;
}
if(url.match(/i\.imgtc\.com/)) {
return true;
}
}
function main() {
var url = location.toString();
if(testOmit(url)) {
return;
}
var suggbox = suggdiv();
jQuery(document.body).css('width','75%').after(suggbox).parent().css({display:'flex','flex-flow':'row'});
var history=GM_getValue('history','[]')
history=JSON.parse(history);
console.log('history',history);
suggmagic(history,url,document.title,(err,rank)=>{
if(err) { return console.log('err',err); }
rank.slice(0,13).forEach(r=>{
suggbox.append(rankitem2div(r));
});
});
history = history.filter(i=>i!=url);
history = history.slice(-16);
history.push(url);
GM_setValue('history',JSON.stringify(history));
}
main();