hwm_clickable_links

Распознавание в тексте ссылок (by ArtPetroff & Demin)

目前为 2015-03-28 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name hwm_clickable_links
  3. // @author Demin
  4. // @namespace Demin
  5. // @description Распознавание в тексте ссылок (by ArtPetroff & Demin)
  6. // @homepage https://greasyfork.org/users/1602-demin
  7. // @icon http://i.imgur.com/LZJFLgt.png
  8. // @version 1.2
  9. // @encoding utf-8
  10. // @include http://*heroeswm.ru/pl_info.php*
  11. // @include http://178.248.235.15/pl_info.php*
  12. // @include http://*lordswm.com/pl_info.php*
  13. // @include http://*heroeswm.ru/forum_messages.php*
  14. // @include http://178.248.235.15/forum_messages.php*
  15. // @include http://*lordswm.com/forum_messages.php*
  16. // @include http://*heroeswm.ru/clan_info.php*
  17. // @include http://178.248.235.15/clan_info.php*
  18. // @include http://*lordswm.com/clan_info.php*
  19. // @grant GM_deleteValue
  20. // @grant GM_getValue
  21. // @grant GM_listValues
  22. // @grant GM_setValue
  23. // @grant GM_addStyle
  24. // @grant GM_log
  25. // @grant GM_openInTab
  26. // ==/UserScript==
  27.  
  28. // (c) 2015, demin ( http://www.heroeswm.ru/pl_info.php?id=15091 )
  29. // (c) 2009, ArtPetroff
  30.  
  31. (function() {
  32.  
  33. var version = '1.2';
  34.  
  35.  
  36. if (typeof GM_getValue != 'function') {
  37. this.GM_getValue=function (key,def) {return localStorage[key] || def;};
  38. this.GM_setValue=function (key,value) {return localStorage[key]=value;};
  39. this.GM_deleteValue=function (key) {return delete localStorage[key];};
  40. }
  41.  
  42.  
  43. var script_num = 8508;
  44. var script_name = "hwm_clickable_links: Распознавание в тексте ссылок (by ArtPetroff & Demin)";
  45. update_n(version,script_num,script_name);
  46.  
  47. var url_cur = location.href;
  48. var url = 'http://'+location.hostname+'/';
  49.  
  50.  
  51. if (url_cur.indexOf("pl_info.php") != -1) {
  52.  
  53. var td_arr = document.getElementsByTagName('td');
  54. td_arr[td_arr.length - 2].innerHTML = replaceAll( td_arr[td_arr.length - 2].innerHTML.split('<br>') );
  55.  
  56. } else if (url_cur.indexOf("forum_messages.php") != -1) {
  57.  
  58. var td_arr = document.getElementsByTagName('td');
  59. for (var i = 0; i < td_arr.length; i++) {
  60. var td = td_arr[i];
  61. var attr = td.getAttribute('style');
  62. if (attr == "color: #000000; padding: 5px; font-size: 13px;") {
  63. td_arr[i].innerHTML = replaceAll( td_arr[i].innerHTML.split('<br>') );
  64. }
  65. }
  66.  
  67. } else if (url_cur.indexOf("clan_info.php") != -1) {
  68.  
  69. var add_table_parent = document.querySelector("a[href^='clan_log.php?id']");
  70. while ( add_table_parent.tagName != 'TABLE' ) { add_table_parent = add_table_parent.parentNode; }
  71. add_table_parent = add_table_parent.lastChild;
  72. add_table_parent.innerHTML = replaceAll( add_table_parent.innerHTML.split('<br>') );
  73. }
  74.  
  75. function replaceAll(lines) {
  76. for (var i = 0; i < lines.length; i++) {
  77. var words = lines[i].split(' ');
  78. for (var j = 0; j < words.length; j++) {
  79. words[j] = replace(words[j]);
  80. }
  81. lines[i] = words.join(' ');
  82. }
  83. return lines.join('<br>');
  84. }
  85.  
  86. function replace(a) {
  87. var b = (a.indexOf("color=") == 0);
  88. var i = a.indexOf("http://");
  89. if (i > 1 && !b) {return a;}
  90. if (i != -1) {
  91. return a.substring(0, i) + "<a href=\"" + a.substring(i) + "\">" + a.substring(i) + "</a>";
  92. }
  93. i = a.indexOf("https://");
  94. if (i > 1) {return a;}
  95. if (i != -1 && !b) {
  96. return a.substring(0, i) + "<a href=\"" + a.substring(i) + "\">" + a.substring(i) + "</a>";
  97. }
  98. i = a.indexOf("ftp://");
  99. if (i > 1) {return a;}
  100. if (i != -1 && !b) {
  101. return a.substring(0, i) + "<a href=\"" + a.substring(i) + "\">" + a.substring(i) + "</a>";
  102. }
  103. return a;
  104. }
  105.  
  106. function $(id) { return document.querySelector("#"+id); }
  107.  
  108. function addEvent(elem, evType, fn) {
  109. if (elem.addEventListener) {
  110. elem.addEventListener(evType, fn, false);
  111. }
  112. else if (elem.attachEvent) {
  113. elem.attachEvent("on" + evType, fn);
  114. }
  115. else {
  116. elem["on" + evType] = fn;
  117. }
  118. }
  119.  
  120. function update_n(a,b,c,d,e){if(e){e++}else{e=1;d=(Number(GM_getValue(b+'_update_script_last2','0'))||0)}if(e>3){return}var f=new Date().getTime();var g=document.querySelector('#update_demin_script2');if(g){if((d+86400000<f)||(d>f)){g=g.innerHTML;if(/100000=1.1/.exec(g)){var h=new RegExp(b+'=(\\d+\\.\\d+)=(\\d+)').exec(g);var i=/url7=([^%]+)/.exec(g);if(a&&h&&i){if(Number(h[1])>Number(a))setTimeout(function(){if(confirm('\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u043E \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u0435 \u0441\u043A\u0440\u0438\u043F\u0442\u0430: "'+c+'".\n\u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u044C \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u0443\u044E \u0432\u0435\u0440\u0441\u0438\u044E \u0441\u0435\u0439\u0447\u0430\u0441?\n\nThere is an update available for the script: "'+c+'".\nWould you like install the script now?')){if(typeof GM_openInTab=='function'){GM_openInTab(i[1].replace(/\s/g,'')+h[2])}else{window.open(i[1].replace(/\s/g,'')+h[2],'_blank')}}},500)}GM_setValue(b+'_update_script_last2',''+f)}else{setTimeout(function(){update_n(a,b,c,d,e)},1000)}}}else{var j=document.querySelector('body');if(j){var k=GM_getValue(b+'_update_script_array2');if(e==1&&((d+86400000<f)||(d>f)||!k)){if(k){GM_deleteValue(b+'_update_script_array2')}setTimeout(function(){update_n(a,b,c,d,e)},1000);return}var l=document.createElement('div');l.id='update_demin_script2';l.setAttribute('style','position: absolute; width: 0px; height: 0px; top: 0px; left: 0px; display: none;');l.innerHTML='';j.appendChild(l);if((d+86400000<f)||(d>f)||!k){var m=new XMLHttpRequest();m.open('GET','photo_pl_photos.php?aid=1777'+'&rand='+(Math.random()*100),true);m.onreadystatechange=function(){update(m,a,b,c,d,e)};m.send(null)}else{document.querySelector('#update_demin_script2').innerHTML=k;setTimeout(function(){update_n(a,b,c,d,e)},10)}}}}function update(a,b,c,d,e,f){if(a.readyState==4&&a.status==200){a=a.responseText;var g=/(\d+=\d+\.\d+(=\d+)*)/g;var h='';var i=/(url7=[^%]+\%)/.exec(a);if(i){h+=i[1]}while((i=g.exec(a))!=null){if(h.indexOf(i[1])==-1){h+=' '+i[1]}};GM_setValue(c+'_update_script_array2',''+h);var j=document.querySelector('#update_demin_script2');if(j){j.innerHTML=h;setTimeout(function(){update_n(b,c,d,e,f)},10)}}}
  121.  
  122. })();