WM Dynamic Grabber Object

This is the dynamic grabber object which is created under the WM version 4.x script

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/6904/27571/WM%20Dynamic%20Grabber%20Object.js

  1. // ==UserScript==
  2. // @name WM Dynamic Grabber Object
  3. // @namespace MerricksdadWMDynamicGrabberObject
  4. // @description This is the dynamic grabber object which is created under the WM version 4.x script
  5. // @license http://creativecommons.org/licenses/by-nc-nd/3.0/us/
  6. // @version 4.0.0.0
  7. // @copyright Charlie Ewing except where noted
  8. // ==/UserScript==
  9.  
  10. //this script requires some functions in the WM Common Library
  11. //this script needs access to a pre-defined JSON object
  12.  
  13.  
  14. (function(){
  15.  
  16. //***************************************************************************************************************************************
  17. //***** Dynamic Grabberrabber Object
  18. //***************************************************************************************************************************************
  19. WM.grabber = {
  20. tests:[],
  21.  
  22. methods:["msg","fromID","fromName","url","body","html","targetID","targetName","caption","title","desc","comments",
  23. "commentorID","commentorName","likeName","likeID","link","either","img","canvas"],
  24.  
  25. init:function(params){try{
  26. params=(params||{});
  27. var testsIn = getOptJSON("dynamics_"+WM.currentUser.profile) || [];
  28. var globalsIn = getOptJSON("dynamics_global") || {};
  29. //import locals and intermix globals we have a placeholder for
  30. if (isArrayAndNotEmpty(testsIn)) {
  31. for (var t=0; t<testsIn.length; t++) {
  32. if (testsIn[t].isGlobal) {
  33. //make sure the global test still exists
  34. var glob=globalsIn[testsIn[t].uniqueID]||null;
  35. if (glob){
  36. //merge global and local data
  37. //this retains our expanded/enabled parts
  38. var merge=mergeJSON(glob, testsIn[t]);
  39. WM.grabber.newTest(merge);
  40. //flag it so we don't import it again below
  41. glob.alreadyUsed=true;
  42. } else {
  43. //global missing, can't import
  44. log("WM.grabber.init: Global test missing, cannot merge");
  45. }
  46. } else {
  47. //load from locals
  48. WM.grabber.newTest(testsIn[t]);
  49. }
  50. }
  51. }
  52. //import all globals not already accounted for
  53. for (var t in globalsIn) {
  54. var glob=globalsIn[t];
  55. //avoid already imported globals
  56. if (!glob.alreadyUsed){
  57. glob.uniqueID=t;
  58. glob.isGlobal=true;
  59. WM.grabber.newTest(glob);
  60. }
  61. }
  62. }catch(e){log("WM.grabber.init: "+e);}},
  63.  
  64. save:function(){try{
  65. var ret=[];
  66. var retGlobal={};
  67. if (isArrayAndNotEmpty(WM.grabber.tests)) {
  68. for (var t=0, len=WM.grabber.tests.length; t<len; t++){
  69. var test=WM.grabber.tests[t];
  70. if (!test.isGlobal) {
  71. //save it locally
  72. ret.push(test.saveableData);
  73. } else {
  74. //make a placeholder locally
  75. ret.push({isGlobal:true, uniqueID:test.uniqueID, enabled:test.enabled, expanded:test.expanded});
  76. //and save it globally
  77. var glob=test.saveableData;
  78. glob.uniqueID=test.uniqueID;
  79. retGlobal[test.uniqueID]=glob;
  80. }
  81. }
  82. }
  83. setOptJSON("dynamics_"+WM.currentUser.profile,ret);
  84. setOptJSON("dynamics_global",retGlobal);
  85. }catch(e){log("WM.grabber.save: "+e);}},
  86.  
  87. newTest:function(params){try{
  88. params=params||{};
  89. var test = new WM.Test(params);
  90. WM.grabber.tests.push(test);
  91. WM.grabber.save();
  92. }catch(e){log("WM.grabber.newTest: "+e);}},
  93.  
  94. importTest:function(){try{
  95. var params=prompt("Input test data",null);
  96. if (params) {
  97. WM.grabber.newTest(JSON.parse(params));
  98. }
  99. }catch(e){log("WM.grabber.importTest: "+e);}},
  100.  
  101. //get the test object with id starting at optional node or at top level
  102. //may return null
  103. getTest:function(id,node){try{
  104. var nodes=(node||WM.grabber.tests);
  105. for (var i=0,len=nodes.length;i<len;i++){
  106. if (nodes[i]["id"]==id) {
  107. return nodes[i];
  108. } else if (nodes[i]["kids"]) {
  109. var ret = WM.grabber.getTest(id,nodes[i]["kids"]);
  110. if (ret) return ret;
  111. }
  112. }
  113. }catch(e){log("WM.grabber.getTest: "+e);}},
  114. };
  115.  
  116. })();

QingJ © 2025

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