Sugg

Provides link suggestions based on the current page, similar to youtube

当前为 2019-02-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Sugg
  3. // @namespace Sugg Systems
  4. // @description Provides link suggestions based on the current page, similar to youtube
  5. // @match *://*/*
  6. // @grant GM_setValue
  7. // @grant GM_getValue
  8. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
  9. // @version 0.0.1.20190228005919
  10. // ==/UserScript==
  11.  
  12.  
  13. function suggdiv() {
  14. var div = $('<body>');
  15. div.css('min-height','100%');
  16. div.css('width','25%');
  17. div.css('display','flex');
  18. div.css('flex-flow','column');
  19. return div;
  20. }
  21.  
  22. function suggmagic(history,url,title,cb) {
  23. $.post('https://sugg.lifelist.pw/',JSON.stringify({history,url,title}),rank=>{
  24. cb(null,rank);
  25. }).fail(err=>{
  26. cb(err);
  27. });
  28. }
  29.  
  30. function rankitem2div(item) {
  31. var div = $('<div>').css('padding','8px');
  32. var a = $('<a>').attr('href',item.href).text(item.title||item.href);
  33. div.append(a);
  34. return div;
  35. }
  36.  
  37. function testOmit(url) {
  38. if(url.match(/google.com\/recaptcha/)) {
  39. return true;
  40. }
  41. }
  42.  
  43.  
  44. function main() {
  45. var url = location.toString();
  46. if(testOmit(url)) {
  47. return;
  48. }
  49. var suggbox = suggdiv();
  50. jQuery(document.body).css('width','75%').after(suggbox).parent().css({display:'flex','flex-flow':'row'});
  51. var history=GM_getValue('history','[]')
  52. history=JSON.parse(history);
  53. console.log('history',history);
  54. suggmagic(history,url,document.title,(err,rank)=>{
  55. if(err) { return console.log('err',err); }
  56. rank.slice(0,13).forEach(r=>{
  57. suggbox.append(rankitem2div(r));
  58. });
  59. });
  60. history = history.filter(i=>i!=url);
  61. history = history.slice(-8);
  62. history.push(url);
  63. GM_setValue('history',JSON.stringify(history));
  64. }
  65.  
  66. main();