Kaskus Anti Lazy Load Image

Early Load All Images w/o waiting for window scroll

  1. // ==UserScript==
  2. // @name Kaskus Anti Lazy Load Image
  3. // @namespace https://gf.qytechs.cn/en/scripts/8094-kaskus-anti-lazy-load-image
  4. // @description Early Load All Images w/o waiting for window scroll
  5. // @author tuxie.forte
  6. // @version 0.1
  7. // @dtversion 150215010
  8. // @timestamp 1424014735738
  9. // @include /^https?://(www\.)?kaskus.co.id/thread/*/
  10. // @include /^https?://(www\.)?kaskus.co.id/lastpost/*/
  11. // @include /^https?://(www\.)?kaskus.co.id/post/*/
  12. // @license (CC) by-nc-sa 3.0
  13. //
  14. // -!--latestupdate
  15. //
  16. // v0.1 - 2015-02-15 . 1424014735738
  17. // Init
  18. //
  19. // -/!latestupdate---
  20. // ==/UserScript==
  21. /*
  22. //
  23. //------
  24. //
  25. // Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
  26. // http://creativecommons.org/licenses/by-nc-sa/3.0/deed.ms
  27. // --------------------------------------------------------
  28. */
  29. (function(){
  30.  
  31. var gvar = function(){};
  32. gvar.sversion = 'v' + '0.1';
  33. gvar.scriptMeta = {
  34. timestamp: 1424014735738 // version.timestamp
  35. ,scriptID: 91051 // script-Id
  36. };
  37. /*
  38. window.alert(new Date().getTime());
  39. */
  40. //========-=-=-=-=--=========
  41. gvar.__DEBUG__ = !1; // development debug
  42. //========-=-=-=-=--=========
  43.  
  44. const GMSTORAGE_PATH = 'GM_';
  45. const KS = 'KEY_SAVE_';
  46.  
  47. //========= Global Var Init ====
  48. var $D=function (q, root, single) {
  49. var el;
  50. if (root && typeof root == 'string') {
  51. root = $D(root, null, true);
  52. if (!root) { return null; }
  53. }
  54. if( !q ) return false;
  55. if ( typeof q == 'object') return q;
  56. root = root || document;
  57. if (q[0]=='/' || (q[0]=='.' && q[1]=='/')) {
  58. if (single) {
  59. return document.evaluate(q, root, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  60. }
  61. return document.evaluate(q, root, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  62. }
  63. else if (q[0]=='.') {
  64. el = root.getElementsByClassName(q.substr(1));
  65. return single ? el[0] : el;
  66. }
  67. else {
  68. return root.getElementById( (q[0]=='#' ? q.substr(1):q.substr(0)) );
  69. }
  70. return root.getElementsByTagName(q);
  71. };
  72.  
  73.  
  74. function init(){
  75. ApiBrowserCheck();
  76.  
  77. // -- let's roll --
  78. // scan all mls-img
  79. var node, images = $D('//img[@class="mls-img"]');
  80. clog("image-males-hits: "+images.snapshotLength+" items");
  81.  
  82. if(images.snapshotLength > 0){
  83. for(var i=0, lg = images.snapshotLength; i<lg; i++) {
  84. node = images.snapshotItem(i);
  85. src = node.getAttribute("data-src");
  86.  
  87. node.setAttribute("src", node.getAttribute("data-src"));
  88. node.removeAttribute("data-src");
  89. addClass("rjn-img", node);
  90. removeClass("mls-img", node);
  91. }
  92. }
  93. } // end-init
  94.  
  95.  
  96.  
  97. // static routine
  98. function trimStr(x) { return x.replace(/^\s+|\s+$/g,""); };
  99. function addClass(cName, Obj){
  100. if( !cName || !Obj ) return;
  101. if( !hasClass(cName, Obj) ) return;
  102. var neocls = (Obj.className ? ' '+trimStr(Obj.className)+' ' : '')+cName;
  103. Obj.setAttribute('class', trimStr(neocls));
  104. }
  105. function hasClass(cName, Obj){
  106. return (' ' + Obj.className + ' ').indexOf(' ' +cName + ' ') > -1;
  107. }
  108. function removeClass(cName, Obj){
  109. if( !cName || !Obj ) return;
  110. if( !hasClass(cName, Obj) ) return;
  111. var neocls = (Obj.className ? ' '+Obj.className+' ' : '');
  112. neocls = trimStr ( neocls.replace(cName, "") ); // replace and trim
  113. Obj.setAttribute('class', neocls);
  114. }
  115.  
  116.  
  117. // play safe with Opera;
  118. //=== BROWSER DETECTION / ADVANCED SETTING
  119. //=============snipet-authored-by:GI-Joe==//
  120. function ApiBrowserCheck() {
  121. //delete GM_log; delete GM_getValue; delete GM_setValue; delete GM_deleteValue; delete GM_xmlhttpRequest; delete GM_openInTab; delete GM_registerMenuCommand;
  122. if(typeof(unsafeWindow)=='undefined') { unsafeWindow=window; }
  123. if(typeof(GM_log)=='undefined') { GM_log=function(msg) { try { unsafeWindow.console.log('GM_log: '+msg); } catch(e) {} }; }
  124. var needApiUpgrade=false;
  125. if(window.navigator.appName.match(/^opera/i) && typeof(window.opera)!='undefined') {
  126. needApiUpgrade=true; gvar.isOpera=true; GM_log=window.opera.postError; clog('Opera detected...',0);
  127. }
  128. if(typeof(GM_setValue)!='undefined') {
  129. var gsv; try { gsv=GM_setValue.toString(); } catch(e) { gsv='.staticArgs.FF4.0'; }
  130. if(gsv.indexOf('staticArgs')>0) {
  131. gvar.isGreaseMonkey=true; gvar.isFF4=false;
  132. clog('GreaseMonkey Api detected'+( (gvar.isFF4=gsv.indexOf('FF4.0')>0) ?' >= FF4':'' )+'...',0);
  133. } // test GM_hitch
  134. else if(gsv.match(/not\s+supported/)) {
  135. needApiUpgrade=true; gvar.isBuggedChrome=true; clog('Bugged Chrome GM Api detected...',0);
  136. }
  137. } else { needApiUpgrade=true; clog('No GM Api detected...',0); }
  138. gvar.noCrossDomain = (gvar.isOpera || gvar.isBuggedChrome);
  139. if(needApiUpgrade) {
  140. //gvar.noCrossDomain = gvar.isBuggedChrome = 1;
  141. clog('Try to recreate needed GM Api...',0);
  142. //OPTIONS_BOX['FLASH_PLAYER_WMODE'][3]=2; OPTIONS_BOX['FLASH_PLAYER_WMODE_BCHAN'][3]=2; // Change Default wmode if there no greasemonkey installed
  143. var ws=null; try { ws=typeof(unsafeWindow.localStorage) } catch(e) { ws=null; } // Catch Security error
  144. if(ws=='object') {
  145. clog('Using localStorage for GM Api.',0);
  146. GM_getValue=function(name,defValue) { var value=unsafeWindow.localStorage.getItem(GMSTORAGE_PATH+name); if(value==null) { return defValue; } else { switch(value.substr(0,2)) { case 'S]': return value.substr(2); case 'N]': return parseInt(value.substr(2)); case 'B]': return value.substr(2)=='true'; } } return value; };
  147. GM_setValue=function(name,value) { switch (typeof(value)) { case 'string': unsafeWindow.localStorage.setItem(GMSTORAGE_PATH+name,'S]'+value); break; case 'number': if(value.toString().indexOf('.')<0) { unsafeWindow.localStorage.setItem(GMSTORAGE_PATH+name,'N]'+value); } break; case 'boolean': unsafeWindow.localStorage.setItem(GMSTORAGE_PATH+name,'B]'+value); break; } };
  148. GM_deleteValue=function(name) { unsafeWindow.localStorage.removeItem(GMSTORAGE_PATH+name); };
  149. } else if(!gvar.isOpera || typeof(GM_setValue)=='undefined') {
  150. clog('Using temporarilyStorage for GM Api.',0); gvar.temporarilyStorage=new Array();
  151. GM_getValue=function(name,defValue) { if(typeof(gvar.temporarilyStorage[GMSTORAGE_PATH+name])=='undefined') { return defValue; } else { return gvar.temporarilyStorage[GMSTORAGE_PATH+name]; } };
  152. GM_setValue=function(name,value) { switch (typeof(value)) { case "string": case "boolean": case "number": gvar.temporarilyStorage[GMSTORAGE_PATH+name]=value; } };
  153. GM_deleteValue=function(name) { delete gvar.temporarilyStorage[GMSTORAGE_PATH+name]; };
  154. }
  155. if(typeof(GM_openInTab)=='undefined') { GM_openInTab=function(url) { unsafeWindow.open(url,""); }; }
  156. if(typeof(GM_registerMenuCommand)=='undefined') { GM_registerMenuCommand=function(name,cmd) { GM_log("Notice: GM_registerMenuCommand is not supported."); }; } // Dummy
  157. if(!gvar.isOpera || typeof(GM_xmlhttpRequest)=='undefined') {
  158. clog('Using XMLHttpRequest for GM Api.',0);
  159. GM_xmlhttpRequest=function(obj) {
  160. var request=new XMLHttpRequest();
  161. request.onreadystatechange=function() { if(obj.onreadystatechange) { obj.onreadystatechange(request); }; if(request.readyState==4 && obj.onload) { obj.onload(request); } }
  162. request.onerror=function() { if(obj.onerror) { obj.onerror(request); } }
  163. try { request.open(obj.method,obj.url,true); } catch(e) { if(obj.onerror) { obj.onerror( {readyState:4,responseHeaders:'',responseText:'',responseXML:'',status:403,statusText:'Forbidden'} ); }; return; }
  164. if(obj.headers) { for(name in obj.headers) { request.setRequestHeader(name,obj.headers[name]); } }
  165. request.send(obj.data); return request;
  166. }; }
  167. } // end needApiUpgrade
  168. GM_getIntValue=function(name,defValue) { return parseInt(GM_getValue(name,defValue),10); };
  169. }
  170. // ----my ge-debug--------
  171. function show_alert(msg, force) {
  172. if(arguments.callee.counter) { arguments.callee.counter++; } else { arguments.callee.counter=1; }
  173. GM_log('('+arguments.callee.counter+') '+msg);
  174. if(force==0) { return; }
  175. }
  176. function clog(msg) {
  177. if(!gvar.__DEBUG__) return;
  178. show_alert(msg);
  179. }
  180.  
  181. //----
  182. init()
  183. })();
  184. /* tF. */

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址