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.20190228140853
  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. if(url.match(/imgoat.com\/uploads/)) {
  42. return true;
  43. }
  44. if(url.match(/phuks.co\/submit/)) {
  45. return true;
  46. }
  47. if(url.match(/\/sign_in/)) {
  48. return true;
  49. }
  50. if(url.match(/i\.imgtc\.com/)) {
  51. return true;
  52. }
  53. }
  54.  
  55.  
  56. function main() {
  57. var url = location.toString();
  58. if(testOmit(url)) {
  59. return;
  60. }
  61. var suggbox = suggdiv();
  62. jQuery(document.body).css('width','75%').after(suggbox).parent().css({display:'flex','flex-flow':'row'});
  63. var history=GM_getValue('history','[]')
  64. history=JSON.parse(history);
  65. console.log('history',history);
  66. suggmagic(history,url,document.title,(err,rank)=>{
  67. if(err) { return console.log('err',err); }
  68. rank.slice(0,13).forEach(r=>{
  69. suggbox.append(rankitem2div(r));
  70. });
  71. });
  72. history = history.filter(i=>i!=url);
  73. history = history.slice(-16);
  74. history.push(url);
  75. GM_setValue('history',JSON.stringify(history));
  76. }
  77.  
  78. main();