w35l3y

Userscripts : Includes Checker

May 14th, 2013
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.     var re = /^\/\/ @require\s+[\w:\.\/]*\/(\d+)\.user\.js/gim,
  3.     text = GM_info.scriptMetaStr,
  4.     warn = [],
  5.     includes = {};
  6.    
  7.     try {
  8.         includes = JSON.parse(GM_getResourceText("includes"));
  9.     } catch (e) {
  10.         GM_log("Resource INCLUDES does not exist or is malformed.");
  11.     }
  12.  
  13.     while (re.exec(text)) {
  14.         var a = RegExp.$1;
  15.         if (a in includes) {
  16.             var i = includes[a].test;
  17.  
  18.             (function recursive (parent, index) {
  19.                 if (index < i.length) {
  20.                     if (parent[i[index]]) {
  21.                         recursive(i[index], ++index);
  22.                     } else {
  23.                         warn.push([i.slice(0, 1 + index).join("."), index, a]);
  24.                     }
  25.                 }
  26.             }(this, 0));
  27.         } else {
  28.             GM_log("#" + a + " is not being managed.");
  29.         }
  30.     }
  31.    
  32.     if (warn.length) {
  33.         alert("[" + GM_info.script.name + "]\nThe installation was succeeded but the required files are missing:\n" + warn.map(function (a) {
  34.             return "#" + a[2] + "\t\t" + a[0];
  35.         }).join("\n") + "\n\nPlease try installing again later.");
  36.     }
  37. }());
Advertisement
Add Comment
Please, Sign In to add comment