Nyaa Helper

文章列表:自動高亮下載超過800的文 內文:自動開啟第一個連結

  1. // ==UserScript==
  2. // @name Nyaa Helper
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  5. // @description 文章列表:自動高亮下載超過800的文 內文:自動開啟第一個連結
  6. // @author Yich
  7. // @include https://sukebei.nyaa.si/*
  8. // @grant GM_openInTab
  9. // @grant window.close
  10. // @grant GM_setValue
  11. //@grant GM_getValue
  12. //@require https://code.jquery.com/jquery-3.3.1.min.js
  13. //@require https://cdnjs.cloudflare.com/ajax/libs/jquery.sticky/1.0.4/jquery.sticky.min.js
  14. //@run-at document-end
  15. // ==/UserScript==
  16.  
  17. //====================文章列表=============================
  18. if( !UrlContains("view")){
  19. var maxWindowOpen = 15;//設定下拉選單開啟文章的間隔
  20. var articles = $(".table-responsive table tr");
  21. var DownloadCount = GM_getValue("DownloadCount",100);//defaultDownloadcount的預設值
  22. $(".sticky-wrapper").remove();
  23. $('.navbar-collapse').append("<div id=\"stickyMenu\"></div>");
  24.  
  25.  
  26. //下載數量若超過此值,就標上success的class
  27. $("#stickyMenu").append("<ul class=\"nav navbar-nav\" style=\"margin-top:10px;margin-right:5px;\"> \
  28. <input type=\"number\" id=\"defaultDownloadcount\" style=\"width:60px\" value="+ DownloadCount +" placeholder=\"高亮指定下載數\" />\
  29. <span style=\"color:red;background-color:white\">Count: <span id=\"matchCount\">0</span></span></ul>");
  30.  
  31. $("#stickyMenu").append("<ul class=\"nav navbar-nav\"style=\"margin-top:10px;margin-right:5px;\"><select id=\"OpenwindowIn////dexDropdown\"></select></ul>");
  32.  
  33. document.getElementById ("defaultDownloadcount").addEventListener("input", function(){
  34. GM_setValue("DownloadCount",this.value);
  35. HighLightArticle(articles,this.value);
  36. GenerateOpenwindowIndexDropDown($("#matchCount").text(),maxWindowOpen);
  37. }, false);
  38.  
  39. HighLightArticle(articles,$("#defaultDownloadcount").val());
  40. GenerateOpenwindowIndexDropDown($("#matchCount").text(),maxWindowOpen);
  41.  
  42. //加入按鈕
  43. $("#stickyMenu").append("<ul class=\"nav navbar-nav\" style=\"margin-top:7px\"><li><button type=\"button\" id=\"btnOpenAll\" class=\"btn btn-success\">開啟高亮文章</button></li></ul>");
  44. //點擊按鈕事件 開啟超過指定瀏覽數的文章
  45. document.getElementById ("btnOpenAll").addEventListener ("click", function(){
  46. var start = $('#OpenwindowIndexDropdown option:selected').val() || 0;//start是目前下拉選單的值
  47. var end = parseInt(parseInt(start)+parseInt(maxWindowOpen));
  48. $(".OverBrowseCount").slice(start, end).each(function() {
  49. var url = "https://"+window.location.hostname + $(this).find("td:eq(1)>a").attr("href");
  50. //console.log($(this).find("td:eq(1)>a").text());
  51. GM_openInTab( url, true );
  52. });
  53. }, false);
  54. //將stickyMenu置頂
  55. $("#stickyMenu").sticky({topSpacing:0,zIndex:9999});
  56.  
  57. }
  58. //將瀏覽數超過指定數量的文章標上success
  59. function HighLightArticle(articles,DownLoadCount){
  60. //移除所有class
  61. articles.removeClass();
  62. var matchCount = 0;
  63. articles.each(function() {
  64. var currentDownloadCount = $(this).find('td:last').html();
  65. if(parseInt(currentDownloadCount) >= parseInt(DownLoadCount)){
  66. $(this).addClass("success").addClass("OverBrowseCount");
  67. matchCount+=1;
  68. }
  69. });
  70. $("#matchCount").html(matchCount);
  71. }
  72.  
  73. //產生用來控制開啟特定範圍的下拉選單
  74. function GenerateOpenwindowIndexDropDown(articleCount,maxWindowOpen){
  75. articleCount = articleCount || 75;
  76. $("#OpenwindowIndexDropdown").find('option').remove();
  77. for(var i=0; i < articleCount/maxWindowOpen; i++)
  78. {
  79. var indexStart = i*maxWindowOpen;
  80. var end = parseInt(parseInt(indexStart)+parseInt(maxWindowOpen));
  81. if(end>articleCount)end=articleCount;
  82. $('#OpenwindowIndexDropdown').append("<option value=\""+indexStart+"\">"+indexStart+"~"+end+"</option>")
  83. }
  84.  
  85. }
  86. //====================文章內文=============================
  87. if(UrlContains("view")){
  88. //取得description區塊的html
  89. var html = $("#torrent-description").html();
  90. var rawHtml = decodeEntities(html);
  91. //找出區塊裡的連結
  92. var reg = /((?:\w+):\/\/([\w@][\w.:@-]+)\/?[\w\.?=%&=\-@\/$,]*)/g;
  93. var url;
  94. while (url = reg.exec(rawHtml)) {
  95. if(!url[1].includes('offkab')&&!url[1].includes('dailyjav')){
  96. //彈出視窗
  97. GM_openInTab( url[1], true );
  98. break;
  99. }
  100. }
  101.  
  102. //按下ctrl+Q自動開啟磁力連結且自動關閉視窗
  103. document.onkeydown =function(e){
  104. e = e || window.event; // for IE to cover IEs window event-object
  105. if(e.which = 18 && e.which == 81){
  106. window.location.href = $('a[href^="magnet"]').attr('href');
  107. window.close();
  108. }
  109. }
  110. //加入說明文字
  111. if(!$("#pluginInfo").length){
  112. $('.navbar-collapse').append("<ul class=\"nav navbar-nav\" style=\"margin-top:15px\"><li><span id=\"pluginInfo\"style=\"color:red\">Ctrl+Q:複製磁力連結&關閉視窗 Ctrl+W:關閉視窗</span></li></ul>");
  113. }
  114. }
  115.  
  116. //=======================utility======================
  117.  
  118. function UrlContains(urlfragment){
  119. return document.URL.indexOf(urlfragment) != -1;
  120. }
  121.  
  122. //url decode
  123. function decodeEntities(encodedString) {
  124. var textArea = document.createElement('textarea');
  125. textArea.innerHTML = encodedString;
  126. return textArea.value;
  127. }
  128. //複製字串到剪貼簿
  129. function copyToClipboard(strbecopy) {
  130. var $temp = $("<input>");
  131. $("body").append($temp);
  132. $temp.val(strbecopy).select();
  133. document.execCommand("copy");
  134. $temp.remove();
  135. }