NGA User Script Loader

NGA User Script Loader 实现两个功能:1.在页面未加载 jQuery 时加载 jQuery ;2.在点击“加载上一页/下一页”按钮后重新运行用户脚本(需脚本自身配合)。

As of 2018-03-01. See the latest version.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/39014/255210/NGA%20User%20Script%20Loader.js

  1. // ==UserScript==
  2. // @name NGA User Script Loader
  3. // @namespace none
  4. // @version 0.0.1.20180302
  5. // @icon http://bbs.nga.cn/favicon.ico
  6. // @description NGA User Script Loader 实现两个功能:1.在页面未加载 jQuery 时加载 jQuery ;2.在点击“加载上一页/下一页”按钮后重新运行用户脚本(需脚本自身配合)。
  7. // @author AgLandy
  8. // @include /^https?:\/\/(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn)/
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function(){
  13.  
  14. if(!window.commonui)
  15. commonui = {};
  16.  
  17. try{
  18. if(commonui.userScriptLoader.$)
  19. return;
  20. }
  21. catch(e){
  22. let btn = 'a[title^="加载"]',
  23. init = function($){
  24. commonui.userScriptLoader = {
  25. $: $,
  26. userScriptData: {},
  27. reload: function(){
  28. let usl = commonui.userScriptLoader;
  29. if(usl.mo)
  30. return;
  31. usl.mo = new MutationObserver(function(){
  32. $(btn).bind('click.userScriptLoader', usl.reload);
  33. $.each(usl.userScriptData, function(k, v){
  34. v();
  35. });
  36. usl.mo.disconnect();
  37. delete usl.mo;
  38. });
  39. usl.mo.observe($('div#mc')[0], {
  40. childList: true,
  41. subtree: true,
  42. });
  43. }
  44. };
  45. console.log('usl is ready');
  46. $(btn).bind('click.userScriptLoader', commonui.userScriptLoader.reload);
  47. };
  48. if(typeof jQuery == 'undefined'){
  49. let s = document.createElement('script');
  50. s.type = 'text/javascript';
  51. s.src = 'https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js';
  52. s.onload = s.onreadystatechange = function(){
  53. if(!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState){
  54. init(jQuery.noConflict());
  55. this.onload = this.onreadystatechange = null;
  56. }
  57. };
  58. document.head.appendChild(s);
  59. }
  60. else
  61. init(jQuery);
  62. }
  63.  
  64. })();