Sugg

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

  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. // @noframes
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
  10. // @version 0.0.1.20190313025650
  11. // ==/UserScript==
  12.  
  13.  
  14. function suggdiv() {
  15. var div = $('<body>');
  16. div.css('min-height','100%');
  17. div.css('width','25%');
  18. div.css('display','flex');
  19. div.css('flex-flow','column');
  20. return div;
  21. }
  22.  
  23. function suggmagic(history,url,title,cb) {
  24. $.post('https://sugg.lifelist.pw/',JSON.stringify({history,url,title}),rank=>{
  25. cb(null,rank);
  26. }).fail(err=>{
  27. cb(err);
  28. });
  29. }
  30.  
  31. function rankitem2div(item) {
  32. var div = $('<div>').css('padding','8px');
  33. var a = $('<a>').attr('href',item.href).text(item.title||item.href);
  34. div.append(a);
  35. return div;
  36. }
  37.  
  38.  
  39. function main(skipnotacheck) {
  40. if(!skipnotacheck && location.host==='notabug.io' && location.pathname.startsWith('/t/') && !location.pathname.startsWith('/t/all')) {
  41. return setTimeout(()=>{
  42. document.title = $('.title.may-blank').first().text();
  43. main(true);
  44. },2000);
  45. }
  46. var url = location.toString();
  47. if(testOmit(url)) {
  48. return;
  49. }
  50. var suggbox = suggdiv();
  51. jQuery(document.body).css('width','75%').after(suggbox).parent().css({display:'flex','flex-flow':'row'});
  52. var history=GM_getValue('history','[]')
  53. history=JSON.parse(history);
  54. console.log('history',history);
  55. suggmagic(history,url,document.title,(err,rank)=>{
  56. if(err) { return console.log('err',err); }
  57. rank.slice(0,13).forEach(r=>{
  58. suggbox.append(rankitem2div(r));
  59. });
  60. });
  61. history = history.filter(i=>i!=url);
  62. history = history.slice(-16);
  63. history.push(url);
  64. GM_setValue('history',JSON.stringify(history));
  65. }
  66.  
  67. main();
  68.  
  69. function regexlist () {
  70. return [
  71. /google.com\/recaptcha/,
  72. /imgoat.com\/uploads/,
  73. /phuks.co\/submit/,
  74. /\/sign_in/,
  75. /i\.imgtc\.com/,
  76. /voat.co\/submit/,
  77. /\login\?/,
  78. /voat\.co\/submit/,
  79. /https?:\/\/searx\.me/,
  80. /https?:\/\/greasyfork.org\/en\/script_versions/,
  81. /porn/,
  82. /facebook.com\/./,
  83. /linkedin.com\/./,
  84. /livejasmine.com/,
  85. /voat.co\/messages/,
  86. /button.flattr.com\/./,
  87. /xhamster.com/,
  88. /xvideos.com/,
  89. /xnxx.com/,
  90. /redtube.com/,
  91. /youporn.com/,
  92. /youtube\.com\/embed\//,
  93. /voat\.co\/v\/\w+\/submit/,
  94. /accounts\.google\.com\//,
  95. /platform\.twitter\.com\/widgets\//,
  96. /\/embed\//,
  97. /poal\.co\/messages/,
  98. ];
  99. }
  100.  
  101. function testOmit(url) {
  102. var tests= regexlist();
  103. for(var c=0;c<tests.length;++c) {
  104. if(url.match(tests[c])) {
  105. return true;
  106. }
  107. }
  108. }