Create Download Links for HACG (https)

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

As of 22.09.2016. See ბოლო ვერსია.

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