Create Download Links for HACG (https)

琉璃神社、灵梦御所、纯爱计划神秘代码转换成下载链接(https版)

Fra og med 22.09.2016. Se den nyeste version.

  1. // ==UserScript==
  2. // @name Create Download Links for HACG (https)
  3. // @namespace hoothin
  4. // @description 琉璃神社、灵梦御所、纯爱计划神秘代码转换成下载链接(https版)
  5. // @author 天涯倦客
  6. // @supportURL http://t.qq.com/HeartBlade
  7. // @include http*://www.hacg.*/wordpress/*
  8. // @include http*://hacg.*/wordpress/*
  9. // @include http*://www.hacg.*/wp/*
  10. // @include http*://hacg.*/wp/*
  11. // @include http*://blog.reimu.net/*
  12. // @include http*://pan.baidu.com/share/*
  13. // @include http*://pan.baidu.com/s/*
  14. // @include http*://sexacg.com/*
  15. // @version 3.19
  16. // @grant none
  17. // @run-at document-end
  18. // ==/UserScript==
  19. (function(){
  20. //度盘填充提取码
  21. if(/baidu/.test(location.href)){
  22. if(location.hash.slice(1)){
  23. document.querySelector("#accessCode").value=location.hash.slice(1);
  24. document.querySelector('#submitBtn').click();
  25. }
  26. return;
  27. }
  28. var codeRule = /(?:提取|访问|密|艾)[码碼]?\s*[:: ]?\s*([a-z\d]{4}|\S*)/i;
  29. if (location.href.indexOf(".reimu.") != -1){
  30. document.querySelector("#main").addEventListener('DOMNodeInserted', function(e) {
  31. var pre = document.querySelector("pre");
  32. if (pre && !document.querySelector("#blockBtn")) {
  33. var blockBtn=document.createElement("button");
  34. blockBtn.id="blockBtn";
  35. blockBtn.type="button";
  36. blockBtn.textContent="好孩子看不到";
  37. blockBtn.style="padding:4px 0;position: relative;width:120px;";
  38. pre.before(blockBtn);
  39.  
  40. var oldDriver = document.querySelector(".entry-content");
  41. var txt=oldDriver.innerHTML.toString();
  42. if(regObj.btih.test(txt)){
  43. var magH=txt.match(regObj.btih);
  44. for (j=0;j<magH.length;j++){
  45. linkArr.btih=hashFunc(magH[j])[3]+'<a href="magnet:?xt=urn:btih:'+hashFunc(magH[j])[2]+'" >磁力链接 </a>';
  46. linkArr.btih+=' →<a href="http://www.torrent.org.cn/Home/Convert/magnet2torrent.html?hash='+hashFunc(magH[j])[2]+'" target="_blank" title="需要先注册登陆">【下载种子】</a>';
  47. linkArr.btih+=' <a href="http://www.btaia.com/torrent/detail/hash/'+hashFunc(magH[j])[2]+'" target="_blank" title="支持Base32,可查看种子内容,需要验证码,长期Invalid CAPTCHA token">【种子详情】</a>';
  48.  
  49. txt=txt.replace(magH[j],linkArr.btih);
  50. }
  51. }
  52. //度娘
  53. txt=txt.replace(regObj.bdshare,linkArr.baidu);
  54. //好盘
  55. txt=txt.replace(regObj.howfile,linkArr.howf);
  56. //短链接
  57. txt=txt.replace(regObj.tcn,linkArr.tcn);
  58. //115
  59. txt=txt.replace(regObj.yyw,linkArr.yyw);
  60. //mega
  61. txt=txt.replace(regObj.mega,linkArr.mega);
  62. oldDriver.innerHTML=txt;
  63. var link;
  64. if (document.querySelectorAll) {
  65. link = document.querySelectorAll('a');
  66. } else {
  67. link = document.getElementsByTagName('a');
  68. }
  69. for (var i = 0, k = link.length; i < k; i++) {
  70. var target=link[i];
  71. if(/baidu.com/i.test(target.href)&&!/(?:eyun|tieba)\.baidu\.com/i.test(target.href)&&!/#/i.test(target.href)){ //正则校验匹配的网盘,豁免 百度企业云盘
  72. if(codeRule.test(target.textContent)){
  73. target.href+='#'+extCode(target);
  74. } else if(target.nextSibling&&codeRule.test(target.nextSibling.textContent)){
  75. if(!/#\S+/i.test(target.href)){
  76. target.href+=/#/i.test(target.href)?extCode(target.nextSibling):('#'+extCode(target.nextSibling));
  77. }
  78. } else if(codeRule.test(target.parentNode.textContent)){
  79. if(!/#\S+/i.test(target.href)) target.href+=/#/i.test(target.href)?extCode(target.nextSibling):('#'+extCode(target.nextSibling));
  80. } else {
  81. var j = 0,
  82. maxParent = 5, //向上遍历的层级
  83. parent = target;
  84. while(j<maxParent) {
  85. j++; //遍历计数
  86. parent = parent.parentNode; //取得父对象
  87. if(parent.tagName=="TR") { //如果父对象是表格,则从表格中提取密码
  88. if(codeRule.test(parent.nextElementSibling.textContent)) {
  89. parent=parent.nextElementSibling;
  90. target.href+='#'+extCode(parent);
  91. break;
  92. }
  93. } else if(codeRule.test(parent.textContent)) { //否则按照常规方式提取密码
  94. target.href+='#'+extCode(parent);
  95. break;
  96. }
  97. if(parent==document.body) break; //如果已经遍历到最顶部,停止遍历
  98. }
  99. }
  100. }
  101. }
  102.  
  103.  
  104. document.querySelector("#blockBtn").addEventListener("click",function(){
  105. if(this.nextSibling.style.display == 'block'){
  106. this.nextSibling.style.display = '';
  107. }else{
  108. this.nextSibling.style.display = 'block';
  109. }
  110. });
  111. }
  112.  
  113.  
  114. });
  115. var pre = document.querySelector("pre");
  116. if (pre && !document.querySelector("#blockBtn")) {
  117. var blockBtn=document.createElement("button");
  118. blockBtn.id="blockBtn";
  119. blockBtn.type="button";
  120. blockBtn.textContent="好孩子看不到";
  121. blockBtn.style="padding:4px 0;position: relative;width:120px;";
  122. pre.before(blockBtn);
  123. }
  124. }
  125.  
  126. var i;
  127. //防爆补丁
  128. var feiZao=document.getElementsByTagName("p1");
  129. var fZLength=feiZao.length;
  130. if (!!fZLength){
  131. for (i=0;i<fZLength;i++){
  132. feiZao[0].parentNode.removeChild(feiZao[0]);
  133. }
  134. }
  135.  
  136. var regObj={ //用于匹配的正则
  137. btih:/(?:[^\/=\|])?([a-fA-F0-9]{40})/g,
  138. bdshare:/\s(b?\/s\/)?(\w{7,8})\b(?:\s+(\w{4}))?(?![\">=])/g, //度娘 类型:/s/1i31aCbb b/s/1i31aCbb >>>其后非?!xxx
  139. howfile:/@?(?:HF|howfile)\/file\/(\w{4,10})\/(\w{8,})\/?/gi, //好盘 类型I:@HF/file/61dbeea7/0c7f2f56/ @howfile/file/61dbeea7/0c7f2f56/
  140. tcn:/\bt\/(\w{7})/g, //t.cn短链接 类型I:t/RZEWYLu
  141. yyw:/(\/lb\/)?(5lb[a-zA-Z0-9]{8,12})/g, //115礼包:/lb/5lbeo3p8eh02
  142. mega:/(?:\.co)?(\.nz\/(#[\w!-]{22,}))/g //.co.nz/#!AZcSmbJA!Q5ZbtIDoQecZc_3Cmc2v_vMaLFJRO6Ctd7uaWdWKqK0
  143. //.nz/#F!Cw9HSQCR!GgOIg9e9FNQGSplRDNxWDw
  144. };
  145. var linkArr=[]; //用于替换的链接
  146. linkArr.btih='';//未定义
  147. linkArr.baidu="<a href='http://pan.baidu.com/s/$1#$2' target='_blank'>度娘:$1</a> $2";
  148. linkArr.howf="<a href='http://howfile.com/file/$1/$2/' target='_blank'>好盘:howfile.com/file/$1/$2</a>";
  149. linkArr.tcn="<a href='http://t.cn/$1' target='_blank'>短链:t.cn/$1</a>";
  150. linkArr.yyw="<a href='http://115.com/lb/$2' target='_blank'>115礼包:$2</a> ";
  151. linkArr.mega="<a href='https://mega.co$1' target='_blank'>MEGA网盘:$2</a>";
  152. //磁链
  153. function hashFunc(hash){ //hash操作
  154. hashWord=hash.match(/^\W*/g)[0];
  155. hash=hash.replace(/[\s\W]*/g, "").toUpperCase();
  156. hashStart=hash.slice(0,2);
  157. hashEnd=hash.slice(-2);
  158. return [hashStart,hashEnd,hash,hashWord];
  159. }
  160.  
  161. function processTxt(target){
  162. var txt=target.innerHTML;
  163. if(regObj.btih.test(txt)){
  164. var magH=txt.match(regObj.btih);
  165. for (j=0;j<magH.length;j++){
  166. linkArr.btih=hashFunc(magH[j])[3]+'<a href="magnet:?xt=urn:btih:'+hashFunc(magH[j])[2]+'" >磁力链接 </a>';
  167. linkArr.btih+=' →<a href="http://www.torrent.org.cn/Home/Convert/magnet2torrent.html?hash='+hashFunc(magH[j])[2]+'" target="_blank" title="需要先注册登陆">【下载种子】</a>';
  168. linkArr.btih+=' <a href="http://www.btaia.com/torrent/detail/hash/'+hashFunc(magH[j])[2]+'" target="_blank" title="支持Base32,可查看种子内容,需要验证码,长期Invalid CAPTCHA token">【种子详情】</a>';
  169.  
  170. txt=txt.replace(magH[j],linkArr.btih);
  171. }
  172. }
  173.  
  174. //度娘
  175. txt=txt.replace(regObj.bdshare,linkArr.baidu);
  176. //好盘
  177. txt=txt.replace(regObj.howfile,linkArr.howf);
  178. //短链接
  179. txt=txt.replace(regObj.tcn,linkArr.tcn);
  180. //115
  181. txt=txt.replace(regObj.yyw,linkArr.yyw);
  182. //mega
  183. txt=txt.replace(regObj.mega,linkArr.mega);
  184. target.innerHTML=txt;
  185. }
  186.  
  187. var content=document.querySelector('.entry-content');
  188. if(location.href.indexOf("sexacg.") != -1)content=document.querySelector('article');
  189. if(content){
  190. if(location.href.indexOf("sexacg.") != -1){
  191. var quote = content.querySelector('.su-quote-inner');
  192. if(quote){
  193. processTxt(quote);
  194. }
  195. }
  196. var oldDrivers = content.querySelectorAll("p");
  197. for(var i=0,k=oldDrivers.length;i<k;i++){
  198. processTxt(oldDrivers[i]);
  199. }
  200. oldDrivers = content.querySelectorAll("td");
  201. for(var i=0,k=oldDrivers.length;i<k;i++){
  202. processTxt(oldDrivers[i]);
  203. }
  204. oldDrivers = content.querySelectorAll("pre");
  205. for(var i=0,k=oldDrivers.length;i<k;i++){
  206. processTxt(oldDrivers[i]);
  207. }
  208. }
  209.  
  210. function extCode(obj){
  211. text=obj.textContent.trim();
  212. var rule=new RegExp('(?:提取|访问)[码碼]?\s*[:: ]?\\s*([a-z\\d]{4})','i');
  213. return rule.test(text)?text.match(rule)[1]:(codeRule.test(text)?text.match(codeRule)[1]:""); //首先尝试使用 提取码|访问码 作为密码匹配的关键字,无效时则使用更完整的匹配规则
  214. }
  215.  
  216. var link;
  217. if (document.querySelectorAll) {
  218. link = document.querySelectorAll('a');
  219. } else {
  220. link = document.getElementsByTagName('a');
  221. }
  222. for (var i = 0, k = link.length; i < k; i++) {
  223. if (/.*http:.*\.hacg\./i.test(link[i].outerHTML)) {
  224. link[i].href = link[i].outerHTML.match(/(?<=href=").*?(?=")/i)[0].replace(/http/, 'https');
  225. }
  226. var target=link[i];
  227. if(/baidu.com/i.test(target.href)&&!/(?:eyun|tieba)\.baidu\.com/i.test(target.href)&&!/#/i.test(target.href)){ //正则校验匹配的网盘,豁免 百度企业云盘
  228. if(codeRule.test(target.textContent)){
  229. target.href+='#'+extCode(target);
  230. } else if(target.nextSibling&&codeRule.test(target.nextSibling.textContent)){
  231. if(!/#\S+/i.test(target.href)){
  232. target.href+=/#/i.test(target.href)?extCode(target.nextSibling):('#'+extCode(target.nextSibling));
  233. }
  234. } else if(codeRule.test(target.parentNode.textContent)){
  235. if(!/#\S+/i.test(target.href)) target.href+=/#/i.test(target.href)?extCode(target.nextSibling):('#'+extCode(target.nextSibling));
  236. } else {
  237. var j = 0,
  238. maxParent = 5, //向上遍历的层级
  239. parent = target;
  240. while(j<maxParent) {
  241. j++; //遍历计数
  242. parent = parent.parentNode; //取得父对象
  243. if(parent.tagName=="TR") { //如果父对象是表格,则从表格中提取密码
  244. if(codeRule.test(parent.nextElementSibling.textContent)) {
  245. parent=parent.nextElementSibling;
  246. target.href+='#'+extCode(parent);
  247. break;
  248. }
  249. } else if(codeRule.test(parent.textContent)) { //否则按照常规方式提取密码
  250. target.href+='#'+extCode(parent);
  251. break;
  252. }
  253. if(parent==document.body) break; //如果已经遍历到最顶部,停止遍历
  254. }
  255. }
  256. }
  257. }
  258. //手动转换文本框
  259. var oD_box=document.createElement("div");
  260. oD_box.id="oD_box";
  261. oD_box.style="position:fixed;top:10px;right:10px; width:210px;";
  262. var oD_text=document.createElement("input");
  263. oD_text.id="oD_text";
  264. oD_text.type="text";
  265. oD_text.placeholder="输入hash值";
  266. oD_text.title='将自动添加"magnet:?xt=urn:btih:",去除[]中的内容、非字母数字字符、空格';
  267. var oD_button=document.createElement("button");
  268. oD_button.id="oD_button";
  269. oD_button.type="button";
  270. oD_button.textContent="开车";
  271. oD_button.style="padding:4px 0; position: relative; top:-1px";
  272. oD_button.onclick=function (){
  273. var oD_hash=oD_text.value.replace(/(\[.*\])|[\W_]/g,"");
  274. oD_link.href="magnet:?xt=urn:btih:"+oD_hash;
  275. oD_link.textContent="磁链";
  276. oD_link2.href="http://www.torrent.org.cn/Home/Convert/magnet2torrent.html?hash="+oD_hash;
  277. oD_link2.textContent="种子";
  278. oD_link2.style="margin-left:20px";
  279. oD_link3.href="http://www.btaia.com/torrent/detail/hash/"+oD_hash;
  280. oD_link3.textContent="详情";
  281. oD_link3.style="margin-left:20px";
  282. };
  283. var oD_link=document.createElement("a");
  284. var oD_link2=document.createElement("a");
  285. var oD_link3=document.createElement("a");
  286. oD_link2.target="_blank";
  287. oD_link3.target="_blank";
  288. oD_box.appendChild(oD_text);
  289. oD_box.appendChild(oD_button);
  290. oD_box.appendChild(oD_link);
  291. oD_box.appendChild(oD_link2);
  292. oD_box.appendChild(oD_link3);
  293. document.body.appendChild(oD_box);
  294. if(document.querySelector("#blockBtn")){
  295. document.querySelector("#blockBtn").addEventListener("click", function(){
  296. if(this.nextSibling.style.display == 'block'){
  297. this.nextSibling.style.display = '';
  298. }else{
  299. this.nextSibling.style.display = 'block';
  300. }
  301. });
  302. }
  303. //评论区度娘、115、tcn
  304. var buDang=document.getElementsByClassName('comment-content');
  305. for (i in buDang){
  306. if(buDang[i]&&buDang[i].innerHTML)
  307. buDang[i].innerHTML=buDang[i].innerHTML.replace(/\b(\w{8})\b(?:\s*(?:<br>|密码:|密码:|pw:|提取码:)?\s*(\w{4}|\S*?(?=\<)|\S*)?)/gi,linkArr.baidu).replace(regObj.yyw,linkArr.yyw).replace(regObj.tcn,linkArr.tcn);
  308. }
  309.  
  310. })();