WM Host Object

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

2014-12-12 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

بۇ قوليازمىنى بىۋاسىتە قاچىلاشقا بولمايدۇ. بۇ باشقا قوليازمىلارنىڭ ئىشلىتىشى ئۈچۈن تەمىنلەنگەن ئامبار بولۇپ، ئىشلىتىش ئۈچۈن مېتا كۆرسەتمىسىگە قىستۇرىدىغان كود: // @require https://update.greatest.deepsurf.us/scripts/6908/27960/WM%20Host%20Object.js

  1. // ==UserScript==
  2. // @name WM Host Object
  3. // @namespace MerricksdadWMHostObject
  4. // @description This is the host 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.3
  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. //*****short text versions for WM.config menu options*****
  17.  
  18. var checkBox=function(l,d,c,n){return ({type:"checkbox",label:l,"default":d||false,kids:c,newitem:n});}
  19. var hidden=function(l,d,c){return ({type:"hidden",label:l,"default":d,kids:c});}
  20. var optionBlock=function(l,c,hideSelectAll,n){hideSelectAll=hideSelectAll||false;return ({type:"optionblock",label:l,kids:c,hideSelectAll:hideSelectAll,newitem:n});}
  21. var separator=function(l,s,c,hideSelectAll){hideSelectAll=hideSelectAll||false; return ({type:"separator",label:l,section:s,kids:c}); }
  22. var section=function(l,c){return ({type:"section",label:l,kids:c});}
  23. var tabSection=function(l,c){return ({type:"tab",label:l,kids:c});}
  24. var inputBox=function(l,d,n){return ({type:"float",label:l,"default":(d||0),newitem:n});}
  25. var textArea=function(l,d,n){return ({type:"textarea",label:l,"default":(d||0),newitem:n});}
  26. var colorBox=function(l,d,n){return ({type:"colorbox",label:l,"default":(d||"black"),newitem:n});}
  27. var button=function(l,s){return ({type:"button",label:l,script:s});}
  28. var anchor=function(l,u,t){return ({type:"link",label:l,href:u,title:(t||'')});}
  29.  
  30. this.WallManager={
  31. paused : false,
  32. fetchPaused : false,
  33. requestsOpen : 0,
  34. reqTO : 30000, //request timeout default
  35. newSidekicks : [],
  36.  
  37. accDefaultText : "Got this!",
  38. failText : "Oh no! Sorry pardner!",
  39. overLimitText : "Limit reached!",
  40.  
  41. version:"4.0.0.3",
  42. currentUser:{
  43. id:"",
  44. profile:"",
  45. alias:""
  46. },
  47. resources:{
  48. iconsURL:GM_getResourceURL("IconSheet")
  49. },
  50. apps:{},
  51. posts:{},
  52. history:{},
  53. config:null,
  54. opts:{},
  55. quickOpts:{},
  56. displayGroups:{},
  57. likeQueue:[],
  58. switches:{
  59. manualAuthToken:true
  60. },
  61.  
  62. statusText : {
  63. "20":"Sidekick returned force accept",
  64. "3":"Marked as accepted by user",
  65. "2":"Responseless Collection",
  66. "1":"Accepted",
  67. "0":"Unknown",
  68. "-1":"Failed",
  69. "-2":"None Left",
  70. "-3":"Over Limit (App)",
  71. "-4":"Over Limit, Sent One Anyway",
  72. "-5":"Server Error",
  73. "-6":"Already Got",
  74. "-7":"Server Down For Repairs",
  75. "-8":"Problem Getting Passback Link",
  76. "-9":"Final Request Returned Null Page",
  77. "-10":"Final Request Failure",
  78. "-11":"Expired",
  79. "-12":"Not a Neighbor",
  80. "-13":"Requirements not met",
  81. "-14":"Timeout",
  82. "-15":"Unrecognized Response",
  83. "-16":"Passback Link is missing",
  84. "-17":"Window Missing",
  85. "-18":"Marked as failed by user",
  86. "-20":"Sidekick returned force fail",
  87. "-19":"Over Limit (Bonus Type)",
  88. "-21":"Cancelled mid-process by user",
  89. },
  90. sortGroups : function(params){
  91. params=params||{};
  92. params.direction=(WM.quickOpts.groupDirection=(params.direction||WM.quickOpts.groupDirection||"desc")); //default descending to keep time ordered posts in order newest to oldest
  93. WM.saveQuickOpts();
  94. //reorder the groups
  95. var groupsArray=[];
  96. for (var g in WM.displayGroups) {
  97. groupsArray.push({id:g,node:WM.displayGroups[g].parentNode,box:WM.displayGroups[g]});
  98. }
  99. if (["asc","ascending"].inArray(params.direction.toLowerCase())) groupsArray.sort(function(a,b){return a.id>b.id;});
  100. else if (["desc","descending"].inArray(params.direction.toLowerCase())) groupsArray.sort(function(a,b){return a.id<b.id;});
  101. WM.displayGroups={};
  102. for (var g=0; g<groupsArray.length; g++) {
  103. WM.displayGroups[groupsArray[g].id]=groupsArray[g].box;
  104. WM.console.feedNode.appendChild(groupsArray[g].node);
  105. }
  106. },
  107.  
  108. newGroup : function(params){
  109. params=params||{};
  110.  
  111. //prevent duplicates
  112. if (WM.displayGroups[params.by]||null) return WM.displayGroups[params.by];
  113. //create the nodes
  114. var box;
  115. var group=createElement("div",{className:"listItem"},[
  116. createElement("div",{className:"line", onclick:function(){
  117. //toggle rollout
  118. with (this.nextSibling) className=className.swapWordB((className.containsWord("collapsed")),"expanded","collapsed");
  119. with (this.firstChild.firstChild) className=className.swapWordB((className.containsWord("treeCollapse"+WM.opts.littleButtonSize)),"treeExpand"+WM.opts.littleButtonSize,"treeCollapse"+WM.opts.littleButtonSize);
  120. }},[
  121. createElement("div",{className:"littleButton",title:"Toggle Content"},[
  122. createElement("img",{className:"resourceIcon treeCollapse"+WM.opts.littleButtonSize}),
  123. ]),
  124. createElement("label",{textContent:params.label||params.by})
  125. ]),
  126. box=createElement("div",{className:"subsection rollout expanded"}),
  127. ]);
  128. //add it to our group list
  129. WM.displayGroups[params.by]=box;
  130. WM.sortGroups();
  131. return box;
  132. },
  133. pauseCollecting : function(doPause){
  134. var isPaused;
  135. if (exists(doPause)) isPaused = (WM.paused = doPause);
  136. else isPaused=(WM.paused = !WM.paused);
  137. var btn=WM.console.pauseCollectButton;
  138. btn.className = btn.className.swapWordB(isPaused,"oddGreen","oddOrange");
  139. btn.title = (isPaused)?"Start Automatic Collection":"Pause Automatic Collection";
  140. var img = btn.childNodes[0];
  141. img.className = img.className.swapWordB(isPaused,"playRight24","stop24");
  142. },
  143.  
  144. pauseFetching : function(doPause){
  145. var isPaused;
  146. if (exists(doPause)) isPaused = (WM.fetchPaused = doPause);
  147. else isPaused=(WM.fetchPaused = !WM.fetchPaused);
  148. var btn=WM.console.pauseFetchButton;
  149. btn.className = btn.className.swapWordB(isPaused,"oddGreen","oddOrange");
  150. btn.title = (isPaused)?"Start Automatic Fetching":"Pause Automatic Fetching";
  151. },
  152.  
  153. clearGroups : function(params){
  154. //destroy previous groups
  155. for (var g in WM.displayGroups){
  156. remove(WM.displayGroups[g].parentNode); //kill the node
  157. delete WM.displayGroups[g]; //remove from list
  158. }
  159. },
  160.  
  161. clearPosts : function(){
  162. //remove all post nodes from the collector panel
  163. for (var p in WM.posts){
  164. if (WM.posts[p].node) remove(WM.posts[p].node);
  165. }
  166. },
  167. constructGroups : function(params){
  168. params=params||{};
  169. //this specifically allows a null so we can remove grouping
  170. var by=exists(params.by)?params.by:WM.quickOpts.groupBy;
  171. //if nothing changed, just cancel
  172. if (by==WM.quickOpts.groupBy) return;
  173. //set the new group order
  174. WM.quickOpts.groupBy=by;
  175. WM.saveQuickOpts();
  176. WM.clearGroups();
  177. },
  178. sortPosts : function(params){
  179. params=params||{};
  180. params.direction=(WM.quickOpts.sortDirection=(params.direction||WM.quickOpts.sortDirection||"desc")); //default descending to keep time ordered posts in order newest to oldest
  181. params.by=(WM.quickOpts.sortBy=(exists(params.by)?params.by:(WM.quickOpts.sortBy||"created_time"))); //default by date
  182. WM.saveQuickOpts();
  183.  
  184. //convert to array
  185. var postsArray=methodsToArray(WM.posts);
  186.  
  187. //sort
  188. postsArray.sort(function(a,b){
  189. if (["ascending","asc"].inArray(params.direction.toLowerCase())) return a[params.by]>b[params.by];
  190. if (["descending","desc"].inArray(params.direction.toLowerCase())) return a[params.by]<b[params.by];
  191. });
  192.  
  193. //convert back to object
  194. WM.posts=arrayToMethods(postsArray);
  195. },
  196.  
  197. doWhichTestTree : function(post, testList, testData, custom) {try{
  198. //match post to an app
  199. var app=post.app;
  200. var synApp=app.synApp, w=null;
  201.  
  202. for (var i=0,test;((test=testList[i]) && (w===null));i++) {
  203.  
  204. //run only for tests that are not specifically disabled
  205. if (test.enabled===false) continue;
  206. //set find mode
  207. var findMode="auto";
  208. //finish constructing dynamic collection tests
  209. var ret = test.ret;
  210. if (custom) {
  211. if (!ret) ret = "dynamic"; //default to dynamic
  212. if (ret!="dynamic" && ret!="none" && ret!="exclude" && !ret.startsWith(synApp.appID)) ret=synApp.appID+ret; //add appID except to magic words
  213. findMode=test.findMode;
  214. }
  215.  
  216. //part to make dynamic collection tests work only if they are the correct appID
  217. //also do not process disabled tests
  218. if (!custom || (custom && (!test.appID || (app.appID==test.appID)))){
  219.  
  220. //if the test is not disabled (by test enabled both existing and being false)
  221. //OR if the test IS a dynamic test and the appID matches
  222. //OR if the test IS a dynamic test and no appID was supplied
  223. //then run the test
  224.  
  225. //detect test type
  226. var testType=(test.search||null);
  227. var types=WM.grabber.methods;
  228. if (!testType) for (var tt=0,len=types.length; tt<len; tt++) {if (test[types[tt]]||"") {testType=types[tt];break;}}
  229.  
  230. //select the type of data to use
  231. var src="";
  232. if (isArray(testType)){ //new search array format
  233. for (var t=0,tlen=testType.length;t<tlen;t++) src+=(testData[testType[t]]||"");
  234. }
  235. else src = (testData[testType]||""); //old test method like testType:text
  236.  
  237. if (src){
  238. //begin processing this test
  239. var subTests=test.subTests, kids=test.kids, allowNone=false, subNumRange=test.subNumRange,text=(test.find||test[testType]||"");
  240.  
  241. //process subtests array
  242. if (subTests && (findMode=="auto" || findMode=="subtests") && text) {
  243. for (var i2=0,subTest,found=false;((subTest=subTests[i2]) && (!found));i2++) {
  244. var testX = text.replace('{%1}',subTest).toLowerCase();
  245.  
  246. //do a standard test with the replaced search string
  247. found=src.find(testX);
  248.  
  249. //return a found value, replacing %1 with a lowercase no-space text equal to the subtest string
  250. w=(found)?ret.replace('{%1}',subTest.noSpaces().toLowerCase()):w;
  251.  
  252. testX=null;
  253. }
  254.  
  255. //process number array
  256. } else if (subNumRange && (findMode=="auto" || findMode=="subnumrange") && text){
  257. var start=parseInt(subNumRange.split(",")[0]), end=parseInt(subNumRange.split(",")[1]);
  258. for (var i2=start,found=false;((!found) && i2<=end);i2++) {
  259. var testX = text.replace('{%1}',i2).toLowerCase();
  260.  
  261. //do a standard test with the replaced search string
  262. found=src.find(testX);
  263.  
  264. //return a found value, replacing %1 with a lowercase no-space text equal to the subtest string
  265. w=(found)?ret.replace('{%1}',i2):w;
  266.  
  267. testX=null;
  268. }
  269.  
  270. //process text array, process similar to subtests
  271. } else if (text && (findMode=="auto" || findMode=="basic") && (isArray(text))) {
  272. for (var i2=0,subTest,found=false;((subTest=text[i2]) && (!found));i2++) {
  273. var testX = subTest.toLowerCase();
  274.  
  275. //do a standard test with the replaced search string
  276. found=src.find(testX);
  277.  
  278. //return the same value no matter which element from the array is found
  279. w=(found)?ret:w;
  280.  
  281. testX=null;
  282. }
  283.  
  284.  
  285. //process regex
  286. } else if (text && (test.regex||test.isRegex||null) ) {
  287. var mods = (test.mods||"gi");
  288. var testRegex = new RegExp(text,mods);
  289. var match=src.match(testRegex);
  290. if (match) match=match[0]; //always take the first match
  291. w=ret||match||w;
  292.  
  293.  
  294.  
  295. //process single text
  296. } else if (text) {
  297. try{
  298. w=(src.find(text.toLowerCase() ))?ret:w;
  299. } catch(e){
  300. log("WM.doWhichTestTree:"+e);
  301. log("--app:"+app.appID);
  302. log("--test:"+JSON.stringify(test));
  303. }
  304. }
  305.  
  306. }
  307.  
  308. //see if test has type 2 subtests (child node tests based on parent test)
  309. w = ((kids && w)?WM.doWhichTestTree(post, kids, testData, custom):w) || w; //if kids return null, default to key found above
  310.  
  311. //if this test tree returned "none", start over with next tree by replacing "none" with null
  312. //true "none" is handled in the which() function below
  313. if (w==="none") w=null;
  314.  
  315.  
  316. }//end custom checker
  317. }
  318.  
  319. return w;
  320. }catch(e){log("WM.doWhichTestTree: "+e);}},
  321.  
  322. which : function(post,params) {try{
  323. //prevent the rules manager from mistaking main as a post object
  324. if (!post) return;
  325. params=params||{};
  326. //match post to an app
  327. var w, app=post.app, synApp=app.synApp;
  328.  
  329. //create various data for the tests to use
  330. if (!params.reid) post.testData = {
  331. title: (post.name||"undefined").toLowerCase(),
  332. msg: (post.message||"undefined").toLowerCase(),
  333. caption: (post.caption||"undefined").toLowerCase(),
  334. desc: (post.description||"undefined").toLowerCase(),
  335. link: (post.linkText||"undefined").toLowerCase(),
  336. url: Url.decode(post.linkHref).toLowerCase(),
  337. img: (post.picture||"undefined").toLowerCase(),
  338. fromName: post.fromName.toLowerCase(),
  339. fromID: post.fromID.toLowerCase(),
  340. targetName: "undefined", //","+post.getTargets("name").join(",").toLowerCase(),
  341. //targetID: "undefined", //","+post.getTargets("id").join(",").toLowerCase(),
  342. canvas: "undefined", //app.namespace.toLowerCase(),
  343. likeName: "undefined", //","+post.getLikes("name").join(",").toLowerCase(),
  344. likeID: "undefined", //","+post.getLikes("id").join(",").toLowerCase(),
  345. comments: "undefined", //post.getComments("message").join(" \n").toLowerCase(),
  346. commentorName: "undefined", //","+post.getComments("name").join(",").toLowerCase(),
  347. commentorID: "undefined", //","+post.getComments("id").join(",").toLowerCase(),
  348. };
  349. var testData=post.testData;
  350.  
  351. //replacement for old options like body, either and html
  352. testData.body = testData.title+testData.caption+testData.desc;
  353. testData.either = testData.link+testData.body;
  354. testData.html = testData.fromID + testData.fromName + testData.targetID + testData.targetName + testData.message
  355. + testData.href + testData.either + testData.img + testData.canvas + testData.likeID + testData.likeName
  356. + testData.commentorID + testData.commentorName + testData.comments;
  357.  
  358. var dynamicTests = WM.grabber.tests;
  359.  
  360. //check user built dynamic tests first if enabled and told to run first
  361. if (WM.opts["dynamic"+app.appID] && WM.opts.dynamicFirst && dynamicTests) {
  362. w=WM.doWhichTestTree(post,dynamicTests, testData, true)||"none";
  363. }
  364.  
  365. //process this game's tests if dynamic didn't already get one
  366. if (w=="none" || !w || w=="") {
  367. w=((tests=synApp.tests)?WM.doWhichTestTree(post,tests, testData):"none")||"none";
  368. }
  369.  
  370. //check user built dynamic tests last if enabled and not told to run first
  371. if (w=="none" || !w || w=="") {
  372. if (WM.opts["dynamic"+app.appID] && !WM.opts.dynamicFirst && dynamicTests) {
  373. w=WM.doWhichTestTree(post,dynamicTests,testData, true)||"none";
  374. }
  375. }
  376.  
  377. //switch to undefined collection if enabled
  378. w=(w==="none" && app.opts["doUnknown"])?"doUnknown":w;
  379.  
  380. return w;
  381. }catch(e){log("WM.which: "+e);}},
  382.  
  383. resetAccepted : function(params) {
  384. params=params||{};
  385. var ask=WM.opts.historyConfirmClear;
  386. if (params.noConfirm || !ask || (ask && confirm("Delete all history for this profile?"))){
  387. doAction(function(){
  388. WM.history={};
  389. setOpt('history_'+WM.currentUser.profile,'{}');
  390. });
  391. }
  392. },
  393.  
  394. onWindowResize : function(){
  395. WM.resizeConsole();
  396. },
  397. onHeartbeat : function(){
  398. if (WM.rulesManager.enabled) {
  399.  
  400. //affect rules at the base level
  401. WM.rulesManager.doEvent("onHeartbeat",{});
  402. //affect rules at the app level
  403. if (WM.opts.heartbeatAffectsApps) {
  404. for (var a in WM.apps) {
  405. (function(){
  406. WM.rulesManager.doEvent("onHeartbeat",WM.apps[a]);
  407. })();
  408. }
  409. }
  410.  
  411. //affect rules at the post level
  412. if (WM.opts.heartbeatAffectsPosts) {
  413. for (var p in WM.posts) if (!WM.posts[p].isGhost) {
  414. (function(){
  415. WM.rulesManager.doEvent("onHeartbeat",WM.posts[p]);
  416. })();
  417. }
  418. }
  419.  
  420. //affect rules at the rule level
  421. if (WM.opts.heartbeatAffectsRules) {
  422. for (var r=0; r<WM.rulesManager.rules.length; r++) {
  423. (function(){
  424. WM.rulesManager.doEvent("onHeartbeat",WM.rulesManager.rules[r]);
  425. })();
  426. }
  427. }
  428.  
  429. //affect rules at the feed and feed filter levels
  430. if (WM.opts.heartbeatAffectsFeeds || WM.opts.heartbeatAffectsFeedFilters) {
  431. var feeds=WM.feedManager.feeds;
  432. for (var f=0,len=feeds.length; f<len; f++) {
  433. //do the feed
  434. if (WM.opts.heartbeatAffectsFeeds) (function(){
  435. WM.rulesManager.doEvent("onHeartbeat",feeds[f]);
  436. })();
  437. //do the feed filters
  438. if (WM.opts.heartbeatAffectsFeedFilters) {
  439. for (var ff in feeds[f].filters){
  440. (function(){
  441. WM.rulesManager.doEvent("onHeartbeat",feeds[f].filters[ff]);
  442. })();
  443. }
  444. }
  445. }
  446. }
  447. }
  448. //check for new sidekick arrivals
  449. if (isArrayAndNotEmpty(WM.newSidekicks)) {
  450. while (WM.newSidekicks.length>0) {
  451. var app=WM.newSidekicks.shift();
  452. app.fetchPosts();
  453. }
  454. }
  455. //check for autolike queue contents
  456. var quePost = WM.checkAutoLikeQue();
  457. if (quePost) {
  458. //log([quePost.fn,quePost.post.id]);
  459. switch (quePost.fn) {
  460. case "like":quePost.post.like();break;
  461. case "comment":quePost.post.comment(quePost.say);break;
  462. }
  463. }
  464. },
  465.  
  466. //this is for when the WM.config and globalConfig settings change
  467. onSave : function() {
  468. //recopy the settings array from WM.config
  469. WM.updateSettingsValues();
  470.  
  471. //hide or show counters
  472. if (WM.opts.showcounters) WM.showCounters(); else WM.hideCounters();
  473.  
  474. //update intervals
  475. WM.setIntervals();
  476.  
  477. //set new user colors
  478. WM.setColors();
  479. //update config settings
  480. WM.changeConfigSettings();
  481.  
  482. //update those settings we use as global variables
  483. WM.changeDebugSettings();
  484. //set console heights
  485. //WM.resizeConsole();
  486. },
  487.  
  488. updateSettingsValues : function(){try{
  489. WM.opts = WM.config.values;
  490. //new: do this for each of the apps too
  491. for (var a in WM.apps) WM.apps[a].opts=WM.apps[a].config.values;
  492. }catch(e){"WM.updateSettingsValues: "+e}},
  493.  
  494. getAccText: function(appID,w,past,status){
  495. var app=WM.apps[appID].synApp;
  496. //detect and use a status code message
  497. if (!(status>-1 || status==-4 || status==-6)) return WM.statusText[status];
  498. //or return a generic message based on post type
  499. else return (w=="dynamic")?"Dynamic Grab"+((past)?"bed":""):(((w.find("send")?"Sen"+((past)?"t":"d")+" ":w.find("wishlist")?"":"G"+((past?"o":"e"))+"t ") + (app.userDefinedTypes[w]||app.accText[w])) || ((past)?WM.accDefaultText:"Get Unknown") || ((w.startsWith(app.appID+"doUnknown"))?"Unknown":"") );
  500. },
  501.  
  502. stopCollectionOf : function(w){
  503. for (var p in WM.posts) if (!WM.posts[p].isGhost && WM.posts[p].which==w) WM.posts[p].stopCollect();
  504. },
  505.  
  506. startCollectionOf : function(w){
  507. for (var p in WM.posts) if (!WM.posts[p].isGhost && WM.posts[p].which==w) WM.posts[p].collect();
  508. },
  509.  
  510. pauseByType : function(app,w){
  511. if (!isArray(w)) w=[w];
  512. //mark as paused all those posts not yet done
  513. for (var p in WM.posts) if (!WM.posts[p].isGhost && w.inArray(WM.posts[p].which)) WM.posts[p].pause();
  514. //store the paused type but dont save it
  515. var a=(app.parent||app);
  516. for (var i=0; i<w.length; i++) {
  517. var t=w[i];
  518. //add it to the array without making a duplicate
  519. if (!a.typesPaused.inArray(t)) {
  520. a.typesPaused.push(t);
  521. //add a visible node
  522. a.typesPausedNode.appendChild(
  523. a.pausedTypesListNodes[t]=createElement("div",{className:"line"},[
  524. createElement("span",{textContent:(a.userDefinedTypes[t]||a.accText[t])+" ("+t+") "}),
  525. createElement("div",{className:"littleButton oddGreen", title:"Unpause Type"},[
  526. createElement("img",{className:"resourceIcon playRight"+WM.opts.littleButtonSize,onclick:function(){
  527. WM.unPauseByType(a,t);
  528. }})
  529. ])
  530. ])
  531. );
  532. }
  533. }
  534. },
  535.  
  536. unPauseByType : function(app,w){
  537. if (!isArray(w)) w=[w];
  538. //unpause all those posts not yet done
  539. for (var p in WM.posts) if (!WM.posts[p].isGhost && w.inArray(WM.posts[p].which)) WM.posts[p].unPause();
  540. //remove paused type from list but dont save it
  541. var a=(app.parent||app);
  542. for (var i=0; i<w.length; i++) {
  543. //remove the visible node
  544. remove (a.pausedTypesListNodes[w[i]]);
  545. //delete the visible node entry
  546. delete a.pausedTypesListNodes[w[i]];
  547. //remove it from the array
  548. a.typesPaused.removeByValue(w[i]);
  549. }
  550. },
  551.  
  552. setAsAccepted : function(comment,status, post) {try{
  553. var app=post.app;
  554. var synApp=app.synApp;
  555. post.state="accepted";
  556. post.status=status;
  557. post.accept();
  558.  
  559. WM.history[post.id]={status:status, date:timeStamp(), which:(post.which||"undefined").removePrefix(synApp.appID), appID:app.appID};
  560. setOptJSON('history_'+WM.currentUser.profile,WM.history);
  561.  
  562. //do friend tracking
  563. if (WM.opts.useFriendTracker && WM.opts.trackAccepted){
  564. WM.friendTracker.trackStatus(post,true);
  565. }
  566.  
  567. var postNode=post.node||$("post_"+post.id);
  568. if (postNode){
  569. var link=selectSingleNode(".//a[contains(@class,'linkText')]",{node:postNode});
  570.  
  571. var text=WM.getAccText(synApp.appID,post.which,true,status);
  572.  
  573. link.textContent = (comment || text || WM.statusText[status] || WM.accDefaultText);
  574. WM.updatePostStatus(post.id);
  575. }
  576.  
  577. app.acceptCount++;
  578.  
  579. //perform the onAccepted event
  580. WM.rulesManager.doEvent("onAccepted",post);
  581.  
  582. //try autolike
  583. try{
  584. if (WM.opts.useautolike && (WM.opts.autolikeall || WM.opts.autolikeaccepted || (WM.opts.autolikesent && (post.which||"undefined").startsWith("send")) )) {
  585. if (!WM.opts["nolike"+app.appID]){
  586. WM.queAutoLike(post);
  587. //post.like();
  588. }
  589. }
  590. } catch(e){log("setAsAccepted: autolike failed: "+e,{level:3});}
  591. //try autocomment
  592. try{
  593. if (WM.opts.useautocomment && (WM.opts.autolikeall || WM.opts.autolikeaccepted || (WM.opts.autolikesent && (post.which||"undefined").startsWith(synApp.appID+"send")) )) {
  594. if (!WM.opts["nolike"+app.appID]){
  595. //setTimeout(function(){post.comment();},100+(WM.opts.autolikedelay*1000));
  596. WM.queAutoComment(post,null);
  597. }
  598. }
  599. } catch(e){log("setAsAccepted: autocomment failed: "+e,{level:3});}
  600. }catch(e){log("WM.setAsAccepted: "+e);}},
  601.  
  602. disableOpt : function(w,app){try{
  603. var targetConfig=(app||null)?app.config:WM.config;
  604. ((app||null)?app.opts:WM.opts)[w]=false;
  605. targetConfig.set(w,false);
  606. targetConfig.save();
  607. debug.print([w,app,false]);
  608. }catch(e){log("WM.disableOpt: "+e);}},
  609.  
  610. enableOpt : function(w,app){try{
  611. var targetConfig=(app||null)?app.config:WM.config;
  612. ((app||null)?app.opts:WM.opts)[w]=true;
  613. targetConfig.set(w,true);
  614. targetConfig.save();
  615. debug.print([w,app,true]);
  616. }catch(e){log("WM.enableOpt: "+e);}},
  617.  
  618. setOpt : function(w,v,app){try{
  619. var targetConfig=(app||null)?app.config:WM.config;
  620. ((app||null)?app.opts:WM.opts)[w]=v;
  621. targetConfig.set(w,v);
  622. targetConfig.save();
  623. debug.print([w,app,v]);
  624. }catch(e){log("WM.setOpt: "+e);}},
  625.  
  626. resetCounters : function(){try{
  627. for (var a in WM.apps) WM.apps[a].resetCounter();
  628. }catch(e){log("WM.resetCounters: "+e);}},
  629.  
  630. setAsFailed : function(comment, status, post){try{
  631. var app=post.app;
  632. var synApp=app.synApp;
  633. var postNode=post.node||$("post_"+post.id);
  634.  
  635. //special effects for timeout and cancelProcess
  636. if ((!WM.opts.failontimeout && status==-14) || status==-21) {
  637. post.state="timeout";
  638. post.timeout();
  639. if (status==-14) WM.rulesManager.doEvent("onTimeout",post);
  640.  
  641. } else {
  642. post.state="failed";
  643. post.fail(); // don't pass true or it will loop here
  644.  
  645. WM.history[post.id]={status:status, date:timeStamp(), which:(post.which||"undefined").removePrefix(synApp.appID), appID:app.appID};
  646. setOptJSON('history_'+WM.currentUser.profile,WM.history);
  647. WM.rulesManager.doEvent("onFailed",post);
  648. }
  649. post.status=status;
  650.  
  651. //do friend tracking
  652. if (WM.opts.useFriendTracker && WM.opts.trackFailed){
  653. WM.friendTracker.trackStatus(post,false);
  654. }
  655. if (postNode) {
  656. var link=selectSingleNode(".//a[contains(@class,'linkText')]",{node:postNode});
  657. if (link) {
  658. //I can see no reason the link should be missing, but since its been proven to fail, here is a patch
  659. link.textContent = (comment || WM.statusText[status] || WM.failText);
  660. }
  661. WM.updatePostStatus(post.id);
  662. }
  663.  
  664. app.failCount++;
  665. //try autolike
  666. try{
  667. if (WM.opts.useautolike && WM.opts.autolikeall) {
  668. if (!WM.opts["nolike"+app.appID]){
  669. WM.queAutoLike(post);
  670. //post.like();
  671. //setTimeout(function(){post.like();},100+(WM.opts.autolikedelay*1000));
  672. }
  673. }
  674. } catch(e){log("setAsFailed: autolike failed: "+e,{level:3});}
  675. //try autocomment
  676. try{
  677. if (WM.opts.useautocomment && WM.opts.autolikeall) {
  678. if (!WM.opts["nolike"+app.appID]){
  679. //setTimeout(function(){post.comment();},100+(WM.opts.autolikedelay*1000));
  680. WM.queAutoComment(post,null);
  681. }
  682. }
  683. } catch(e){log("setAsFailed: autocomment failed: "+e,{level:3});}
  684. }catch(e){log("WM.setAsFailed: "+e);}},
  685.  
  686. setPriority : function(){
  687. var postNode=selectSingleNode(".//ancestor::*[starts-with(@id,'post_')]",{node:this});
  688. var id=postNode.id.replace("post_","");
  689. WM.posts[id]["priority"]=this.getAttribute("name");
  690. remove(postNode);
  691. WM.posts[id].draw();
  692. },
  693.  
  694. clearURL : function(tab){
  695. WM.collector.close(tab);
  696. WM.requestsOpen--;
  697. },
  698. //constantly update sidekick channel data
  699. skChannel : {},
  700. fetchSidekickData : function(){try{
  701. if (WM) {
  702. var node=selectSingleNode("./div",{node:$("wmDataDump")});
  703. while (node){
  704. log("WM.fetchSidekickData: found "+JSON.parse(node.getAttribute("data-ft")));
  705. WM.skChannel=mergeJSON(WM.skChannel,JSON.parse(node.getAttribute("data-ft")));
  706. remove(node);
  707. node=selectSingleNode("./div",{node:$("wmDataDump")});
  708. }
  709. setTimeout(WM.fetchSidekickData,1000);
  710. }
  711. }catch(e){log("WM.fetchSidekickData: "+e);}},
  712. //this is WM3's method of handling conversations with sidekicks
  713. onFrameLoad3 : function(tab){try{
  714. log("onFrameLoad3(): tab="+tab.id);
  715. var postID=tab.postID||tab.id;
  716. var post=tab.post||WM.posts[postID];
  717.  
  718. //detect if post process was cancelled by user
  719. if (post.processCancelled){
  720. //reset the cancel memory
  721. post.processCancelled = false;
  722. log("onFrameLoad3: process cancelled by user");
  723. //set the timeout flag even though its not timed out
  724. WM.setAsFailed(null,-21,post);
  725. WM.clearURL(tab);
  726. return;
  727. }
  728.  
  729. //detect if valid WM.collector window still exists
  730. var windowExists=(tab.hwnd && !tab.hwnd.closed);
  731. /*try{
  732. var testUrl=tab.hwnd.location.toString();
  733. } catch(e) {
  734. windowExists=false;
  735. }*/
  736. //make sure the post object still exists
  737. if (!(post||null)){
  738. log("onFrameLoad3: post is null");
  739. WM.clearURL(tab);
  740. return;
  741. }
  742.  
  743. //check if window object is missing
  744. if (!windowExists) {
  745. log("windowExists = false");
  746. if (!tab.hwnd) log("onFrameLoad3: tab.hwnd is null");
  747. if (tab.hwnd.closed) log("onFrameLoad3: tab.hwnd is closed");
  748. WM.setAsFailed(null,-17,post);
  749. WM.clearURL(tab);
  750. return;
  751. }
  752. //check timer on this open post
  753. var openTime=tab.openTime;
  754. var nowTime=timeStamp();
  755. if ((WM.opts.reqtimeout*1000)<(nowTime-openTime)){
  756. log("onFrameLoad3: post timed out");
  757. WM.setAsFailed(null,-14,post);
  758. WM.clearURL(tab);
  759. return;
  760. }
  761. //create the retry function
  762. var retry=function(){setTimeout(function(){WM.onFrameLoad3(tab); return;},1000); return;};
  763. //look for status data
  764. var tabID = tab.id;
  765. var skData = WM.skChannel[tabID]||null;
  766. if (skData) {
  767. //data exists for this post
  768. if (skData.status) {
  769. //status is available
  770. delete WM.skChannel[tabID];
  771. //get useful post data
  772. var app=post.app; var synApp=app.parent||app;
  773. var postNode=post.node||$("post_"+post.id);
  774. var link=selectSingleNode(".//a[contains(@class,'linkText')]",{node:postNode});
  775. var w=post.which||"undefined";
  776. //confirm status
  777. var gotItem=((skData.status>0) || (skData.status==-6) || (skData.status==-4) || (skData.status==-15 && WM.opts.accepton15));
  778. var failedItem=(skData.status<0);
  779. if (gotItem){
  780. //build debug block
  781. switch(skData.status){
  782. case -6: case -4: case 1:
  783. // this bonus is available or we still have the ability to send something for no return
  784. //dont break before next
  785. case -15: case 2:
  786. if (!synApp.flags.requiresTwo){
  787. WM.setAsAccepted(null, skData.status, post);
  788. }
  789. break;
  790.  
  791. default:
  792. //should not have come here for any reason, but if we did assume its a status code I didnt script for
  793. WM.setAsFailed(null, skData.status, post);
  794. log("onFrameLoad3: unexpected status code: "+skData.status,{level:2});
  795. break;
  796. }
  797. } else {
  798. WM.setAsFailed(null,skData.status,post);
  799. }
  800. // click "yes" to accept it, if we got this far we actually found an accept button
  801. if(synApp.flags.requiresTwo && gotItem) {
  802. if (skData.nopopLink) {
  803. var req; req=GM_xmlhttpRequest({
  804. method: "GET",
  805. url: skData.nopopLink,
  806. timeout: WM.opts.reqtimeout*1000,
  807. onload: function(response) {
  808. //search for error messages
  809. var test=response.responseText;
  810. if (test==""){
  811. //no text was found at requested href
  812. log("onFrameLoad3: final stage: null response",{level:2});
  813. WM.setAsFailed(null, -9,post);
  814. } else {
  815. //if no errors then we got it
  816. WM.setAsAccepted(null, skData.status,post);
  817. }
  818. WM.clearURL(tab);
  819. if(req)req=null;
  820. },
  821.  
  822. onerror: function(response) {
  823. log("onFrameLoad3: final stage: error returned",{level:2});
  824. //if final request fails, drop the request for now
  825. WM.setAsFailed(null, -10,post);
  826. WM.clearURL(tab);
  827. if(req)req=null;
  828. },
  829.  
  830. onabort: function(response) {
  831. log("onFrameLoad3: final stage: request aborted",{level:2});
  832. WM.setAsFailed(null, -10,post);
  833. WM.clearURL(tab);
  834. if(req)req=null;
  835. },
  836. ontimeout: function(response) {
  837. log("onFrameLoad3: final stage: request timeout",{level:2});
  838. WM.setAsFailed(null, -10,post);
  839. WM.clearURL(tab);
  840. if(req)req=null;
  841. },
  842. });
  843.  
  844. } else {
  845. log("onFrameLoad3: skData.nopopLink is null and a string was expected",{level:3});
  846. WM.setAsFailed(null, -16,post);
  847. WM.clearURL(tab);
  848. return;
  849. }
  850. } else WM.clearURL(tab); //<- default page clearer, do not remove
  851. } else retry();
  852. } else {
  853. retry();
  854. //send the tab its init message (again)
  855. tab.hwnd.postMessage({
  856. channel:"WallManager",
  857. msg:1,
  858. tabID:tab.id,
  859. },"*");
  860. //log("useGM_openInTab: "+WM.opts.useGM_openInTab);
  861. }
  862. }catch(e){log("WM.onFrameLoad3: "+e);}},
  863. //this is WM1-2's method of handling conversation with sidekicks
  864. //WM3 defaults to this if sidekick is not WM3 compatible
  865. onFrameLoad : function(tab,noDebug){try{
  866. //tab object contains {id,post,url}
  867. if (!noDebug) log("onFrameLoad()",{level:0});
  868.  
  869. var id=tab.id; var post=tab.post||WM.posts[id];
  870. if (!(post||null)) {
  871. //resource deleted while post was out
  872. WM.clearURL(tab);
  873. return;
  874. }
  875.  
  876. //detect if post process was cancelled by user
  877. if (post.processCancelled){
  878. //reset the cancel memory
  879. post.processCancelled = false;
  880. log("onFrameLoad3: process cancelled by user");
  881. //set the timeout flag even though its not timed out
  882. WM.setAsFailed(null,-21,post);
  883. WM.clearURL(tab);
  884. return;
  885. }
  886.  
  887. var app=post.app;
  888. var synApp=app.parent||app;
  889.  
  890. var httpsTrouble=synApp.flags.httpsTrouble;
  891. var responseLess=synApp.flags.skipResponse;
  892.  
  893. var postNode=post.node||$("post_"+post.id);
  894. var link=selectSingleNode(".//a[contains(@class,'linkText')]",{node:postNode});
  895. var w=post.which||"undefined";
  896.  
  897. tab.tries=(tab.tries||0)+1;
  898. if (tab.tries>WM.opts.reqtimeout) {
  899. log("onFrameLoad: request timeout",{level:3});
  900. WM.setAsFailed(null, -14, post);
  901. WM.clearURL(tab);
  902. return;
  903. }
  904.  
  905. var retry=function(){setTimeout(function(e){WM.onFrameLoad(tab, true);}, 1000);};
  906.  
  907. var failedItem=false, gotItem=false, nopopLink;
  908.  
  909. //check if window object is missing
  910. var windowExists=(tab.hwnd && !tab.hwnd.closed);
  911. if (!windowExists) {WM.setAsFailed(null,-17,post); WM.clearURL(tab); return;}
  912. //check if window document does not yet exist
  913. //if (!(tab.hwnd.document||null)) {retry(); return;}
  914.  
  915. //get sidekick return value
  916. var hashMsg="",hashStatus=0;
  917. try{
  918. //if error encountered, reload the page
  919. if (tab.hwnd.document.title==="Problem loading page"){
  920. log("processPosts: problem loading page",{level:1});
  921. tab.hwnd.location.reload();
  922. retry();
  923. return;
  924. }
  925.  
  926. var temphash = tab.hwnd.location.hash; //capture a hash if we can
  927. hashMsg = ((temphash)?temphash.removePrefix("#"):null) || tab.hwnd.location.href.split("#")[1];
  928. hashStatus=(responseLess)?2:(hashMsg||null)?parseInt(hashMsg.split('status=')[1].split("&")[0]):0;
  929. gotItem=((hashStatus>0) || (hashStatus==-6) || (hashStatus==-4) || (hashStatus==-15 && WM.opts.accepton15));
  930. failedItem=(hashStatus<0);
  931. if (!gotItem && !failedItem) {retry(); return;}
  932.  
  933. } catch(e){
  934. var errText=""+e;
  935. if (errText.contains("hashMsg is undefined")) {
  936. //this known issue occurs when a page is not yet fully loaded and the
  937. //WM script tries to read the page content
  938. retry();
  939. return;
  940. }
  941. else if (errText.contains("Permission denied to access property")) {
  942. //we've reached some known cross domain issue
  943. if (responseLess) {
  944. //if the sidekick creator has chosen to use responseless collection
  945. //simply assume the page has loaded and mark the item as collected
  946.  
  947. gotItem=true;failedItem=false;hashStatus=2;
  948. } else {
  949. console.log("WM.onFrameLoad(before retry): "+e);
  950. retry();
  951. return;
  952. }
  953. }
  954. else if (errText.contains("NS_ERROR_INVALID_POINTER")
  955. || errText.contains("tab.hwnd.document is null") ) {
  956.  
  957. WM.setAsFailed(null,-17,post);
  958. WM.clearURL(tab);
  959. return;
  960. }
  961. else {
  962. log("onFrameLoad: "+e,{level:3});
  963. retry();
  964. return;
  965. }
  966. }
  967.  
  968. //if gotItem then we have been offered the item so far
  969. if (gotItem){
  970. //build debug block
  971. switch(hashStatus){
  972. case -6: case -4: case 1:
  973. // this bonus is available or we still have the ability to send something for no return
  974. if (synApp.flags.requiresTwo){
  975. try{
  976. nopopLink=hashMsg.split("&link=[")[1].split("]")[0];
  977. }catch(e){
  978. //known rare issue where no link is passed back by pioneer trail
  979. }
  980. }
  981. //dont break before next
  982. case -15: case 2:
  983. if (!synApp.flags.requiresTwo){
  984. WM.setAsAccepted(null, hashStatus,post);
  985. }
  986. break;
  987.  
  988. default:
  989. //should not have come here for any reason, but if we did assume its a status code I didnt script for
  990. WM.setAsFailed(null, hashStatus,post);
  991. log("onFrameLoad: unexpected status code: "+hashStatus,{level:2});
  992. break;
  993. }
  994. } else {
  995. WM.setAsFailed(null,hashStatus,post);
  996. }
  997.  
  998.  
  999. // click "yes" to accept it, if we got this far we actually found an accept button
  1000. if(synApp.flags.requiresTwo && gotItem) {
  1001. if (nopopLink) {
  1002. var req; req=GM_xmlhttpRequest({
  1003. method: "GET",
  1004. url: nopopLink,
  1005. timeout: WM.opts.reqtimeout*1000,
  1006. onload: function(response) {
  1007. //search for error messages
  1008. var test=response.responseText;
  1009. if (test==""){
  1010. //no text was found at requested href
  1011. log("onFrameLoad: final stage: null response",{level:2});
  1012. WM.setAsFailed(null, -9,post);
  1013. } else {
  1014. //if no errors then we got it
  1015. WM.setAsAccepted(null, hashStatus,post);
  1016. }
  1017. WM.clearURL(tab);
  1018. if(req)req=null;
  1019. },
  1020.  
  1021. onerror: function(response) {
  1022. log("onFrameLoad: final stage: error returned",{level:2});
  1023. //if final request fails, drop the request for now
  1024. WM.setAsFailed(null, -10,post);
  1025. WM.clearURL(tab);
  1026. if(req)req=null;
  1027. },
  1028.  
  1029. onabort: function(response) {
  1030. log("onFrameLoad: final stage: request aborted",{level:2});
  1031. WM.setAsFailed(null, -10,post);
  1032. WM.clearURL(tab);
  1033. if(req)req=null;
  1034. },
  1035. ontimeout: function(response) {
  1036. log("onFrameLoad: final stage: request timeout",{level:2});
  1037. WM.setAsFailed(null, -10,post);
  1038. WM.clearURL(tab);
  1039. if(req)req=null;
  1040. },
  1041. });
  1042.  
  1043. } else {
  1044. log("onFrameLoad: nopopLink is null and a string was expected",{level:3});
  1045. WM.setAsFailed(null, -16,post);
  1046. WM.clearURL(tab);
  1047. return;
  1048. }
  1049. } else WM.clearURL(tab);
  1050.  
  1051. }catch(e){log("WM.onFrameLoad: "+e);}},
  1052.  
  1053. toggle : function(opt,app){
  1054. var targetConfig=(app||null)?app.config:WM.config;
  1055. var targetOpts=(app||null)?app.opts:WM.opts;
  1056. if (targetOpts[opt]){
  1057. targetConfig.set(opt, false);
  1058. targetOpts[opt] = false;
  1059. } else {
  1060. targetConfig.set(opt, true);
  1061. targetOpts[opt] = true;
  1062. }
  1063. targetConfig.save();
  1064. },
  1065.  
  1066. getAppDropDownList : function(selectedIndex,allowBlank){
  1067. var retApps=[];
  1068. //add the fake initial option
  1069. retApps.push(createElement("option",{textContent:"select an app",value:""}));
  1070. retApps.push(createElement("option",{textContent:"* All",value:""}));
  1071. if (allowBlank) retApps.push(createElement("option",{textContent:"all apps",value:""}));
  1072.  
  1073. for(var i in WM.apps){
  1074. if (!WM.apps[i].parent) {
  1075. var elem = createElement("option",{textContent:WM.apps[i].name,value:i});
  1076. if ((selectedIndex||null) == i) elem.selected = true;
  1077. retApps.push(elem);
  1078. }
  1079. }
  1080. return retApps;
  1081. },
  1082.  
  1083. getBonusDropDownList : function(params){
  1084. params=params||{};
  1085. var selected = params.selected||"";
  1086. var appID = params.appID||null;
  1087. var dropID = params.dropID||false; //force the element value to drop its appID prefix
  1088.  
  1089. var optsret=[], bonuses={};
  1090. if (appID) bonuses = mergeJSON(WM.apps[appID].accText,WM.apps[appID].userDefinedTypes);
  1091. bonuses["dynamic"]="* Dynamic: Just Grab It";
  1092. bonuses["none"]="* None: Break Identification Circuit";
  1093. bonuses["wishlist"]="* Flag as Wishlist";
  1094. bonuses["exclude"]="* Exclude: Prevent Collection";
  1095. bonuses["send"]="* Send Unknown";
  1096. bonuses["doUnknown"]="* Get Unknown";
  1097.  
  1098. //create option values and names;
  1099. for (var i in bonuses) {
  1100. var elem
  1101. if (appID) elem = createElement("option",{textContent:((i.startsWith(appID+"send"))?"Send ":((bonuses[i].substring(0,1)=="*")?"":"Get "))+bonuses[i],value:((dropID)?i.removePrefix(appID):i)});
  1102. else elem = createElement("option",{textContent:bonuses[i],value:i});
  1103.  
  1104. if (appID) {if (selected==((dropID)?i.removePrefix(appID):i) ) elem.selected = true;}
  1105. else {if (selected==i) elem.selected=true;}
  1106.  
  1107. optsret.push(elem);
  1108. }
  1109.  
  1110. return optsret;
  1111. },
  1112.  
  1113. reIDAll : function(){
  1114. for (var p in WM.posts) {
  1115. if (!WM.posts[p].isGhost && WM.posts[p].identify({reid:true}))
  1116. WM.rulesManager.doEvent("onIdentify",WM.posts[p]);
  1117. }
  1118. WM.sortPosts(); //in this case sorting may cancel movetotop and movetobottom
  1119. WM.clearGroups();
  1120. WM.redrawPosts({postRedraw:true});
  1121. },
  1122.  
  1123. updatePostStatus : function(id){
  1124. var status = WM.posts[id].status;
  1125. var statusNode = selectSingleNode(".//*[contains(@class,'status')]",{node:$("post_"+id)});
  1126. if (statusNode) statusNode.textContent="Status: "+(status||"0") + " " + (WM.statusText[status||"0"]);
  1127. status=null; statusNode=null;
  1128. },
  1129.  
  1130. onLikePost : function(post){
  1131. post.isLiked=true;
  1132. return;
  1133. //pre beta 40 stuff
  1134. var postID=tab.id;
  1135. var post=tab.post||WM.posts[postID];
  1136.  
  1137. //detect if post process was cancelled by user
  1138. if (post.processCancelled){
  1139. //reset the cancel memory
  1140. post.processCancelled = false;
  1141. log("onLikePost: feedback cancelled by user");
  1142. WM.collector.close(tab);
  1143. return;
  1144. }
  1145.  
  1146. //detect if valid WM.collector window still exists
  1147. var windowExists=(tab.hwnd && !tab.hwnd.closed);
  1148.  
  1149. //check if window object is missing
  1150. if (!windowExists) {
  1151. log("onLikePost: tab.hwnd is null or closed");
  1152. WM.collector.close(tab);
  1153. return;
  1154. }
  1155. try{
  1156. var like=tab.hwnd.location.hash.removePrefix("#").getUrlParam("status")=="1";
  1157. if (like) {
  1158. if (tab.post) {
  1159. //tell the post it is liked
  1160. tab.post.isLiked = true;
  1161. //delete the post reference from the tab
  1162. delete tab.post;
  1163. }
  1164. WM.collector.close(tab);
  1165. return;
  1166. }
  1167. } catch (e){
  1168. //log(""+e);
  1169. }
  1170.  
  1171. tab.tries=(tab.tries||0)+1;
  1172. if (tab.tries<WM.opts.autoliketimeout) setTimeout(function(){WM.onLikePost(tab);}, 1000);
  1173. else {
  1174. log("onLikePost: unable to finish feedback",{level:3});
  1175. doAction(function(){WM.collector.close(tab);});
  1176. }
  1177. },
  1178.  
  1179. toggleSidekick : function(){
  1180. var appID = this.id.split("master_")[1];
  1181. var opt = !(WM.quickOpts["masterSwitch"][appID]||false); //toggle
  1182. WM.quickOpts["masterSwitch"][appID]=opt;
  1183. var className = this.parentNode.className;
  1184. this.parentNode.className = ((opt)?className.removeWord("disabled"):className.addWord("disabled"));
  1185. this.textContent=((opt)?"Disable":"Enable");
  1186. WM.saveQuickOpts();
  1187. },
  1188.  
  1189. saveQuickOpts : function(){
  1190. setOptJSON('quickopts_'+WM.currentUser.profile, WM.quickOpts);
  1191. },
  1192.  
  1193. setAppFilter : function(tab){
  1194. WM.quickOpts.filterApp=tab.appFilter;
  1195. WM.saveQuickOpts();
  1196. WM.clearGroups();
  1197. WM.redrawPosts({postRedraw:false,reorder:true});
  1198. WM.rulesManager.doEvent("onSetAppFilter",WM.apps[tab.appFilter]);
  1199. //debug.print(["Collection Tab Selected",WM.currentAppTab,WM.apps[tab.appFilter]]);
  1200. },
  1201. setDisplay : function(){
  1202. var x=this.getAttribute("name");
  1203. WM.quickOpts.displayMode=x;
  1204. WM.saveQuickOpts();
  1205. WM.redrawPosts({postRedraw:true,reorder:true});
  1206. WM.setDisplayCols();
  1207. },
  1208. setDisplayCols : function(params){
  1209. params=params||{};
  1210. params.cols=params.cols||WM.quickOpts.displayCols;
  1211. WM.quickOpts.displayCols=params.cols||1;
  1212. WM.saveQuickOpts();
  1213. with (WM.console.feedNode) {
  1214. className=className
  1215. .toggleWordB(params.cols==1,"singleCol")
  1216. .toggleWordB(params.cols==2,"twoCol")
  1217. .toggleWordB(params.cols==3,"threeCol")
  1218. .toggleWordB(params.cols==4,"fourCol");
  1219. }
  1220. },
  1221.  
  1222. redrawPosts : function(params){
  1223. params=params||{};
  1224. var feedNode=WM.console.feedNode;
  1225. //set the proper display mode
  1226. feedNode.className=feedNode.className
  1227. .toggleWordB((WM.quickOpts.displayMode=="1" || WM.quickOpts.displayMode=="3"),"short");
  1228. //avoid order issues by removing the posts from the panel
  1229. WM.clearPosts();
  1230.  
  1231. //redraw||reorder
  1232. for (var p in WM.posts) {
  1233. var post=WM.posts[p];
  1234. if (!post.isGhost) {
  1235. post.draw(params.postRedraw,params.reorder);
  1236. }
  1237. }
  1238. },
  1239.  
  1240. moveFloater : function(ev){
  1241. if (isChrome) return;
  1242. var img=this, offset=trueOffset(img), scrolled=trueScrollOffset(img),
  1243. post=selectSingleNode(".//ancestor::div[starts-with(@id,'post')]",{node:img}),
  1244. floater=$(post.id.replace("post","floater")), special={};
  1245.  
  1246. //log( (scrolled.left) +","+ (scrolled.top) );
  1247.  
  1248. special.x=(ev.clientX > (document.documentElement.clientWidth/2))?-(240+4+22):0; //width+overshot+BorderAndPadding
  1249. special.y=(ev.clientY > (document.documentElement.clientHeight/2))?-(120+4+12):0;
  1250.  
  1251. floater.style.left=(ev.clientX-(offset.left-scrolled.left))+(2+special.x)+"px";
  1252. floater.style.top=(ev.clientY-(offset.top-scrolled.top))+(2+special.y)+"px";
  1253. },
  1254. //create a drip system for autolike, instead of an offset
  1255. queAutoLike : function(post){
  1256. var nowTime = timeStamp();
  1257. var lastInQue = WM.likeQueue.last();
  1258. var targetTime = nowTime + (1000*WM.opts.autolikedelay);
  1259. if (lastInQue||null) {
  1260. if (lastInQue.timer>nowTime) {
  1261. targetTime = lastInQue.timer + (1000*WM.opts.autolikedelay);
  1262. }
  1263. }
  1264. WM.likeQueue.push({post:post, timer:targetTime, fn:"like"});
  1265. WM.console.likeQueueCounterNode.textContent = WM.likeQueue.length;
  1266. },
  1267. //create a drip system for autolike, instead of an offset
  1268. queAutoComment : function(post,say){
  1269. var nowTime = timeStamp();
  1270. var lastInQue = WM.likeQueue.last();
  1271. var targetTime = nowTime + (1000*WM.opts.autolikedelay);
  1272. if (lastInQue||null) {
  1273. if (lastInQue.timer>nowTime) {
  1274. targetTime = lastInQue.timer + (1000*WM.opts.autolikedelay);
  1275. }
  1276. }
  1277. WM.likeQueue.push({post:post, timer:targetTime, say:say, fn:"comment"});
  1278. WM.console.likeQueueCounterNode.textContent = WM.likeQueue.length;
  1279. //log(["autocomment added",say]);
  1280. },
  1281.  
  1282. //dump the autolike queue
  1283. emptyAutoLikeQue : function() {
  1284. WM.likeQueue=[];
  1285. WM.console.likeQueueCounterNode.textContent = 0;
  1286. },
  1287. //get the next ready autolike target
  1288. checkAutoLikeQue : function() {
  1289. if (WM.likeQueue.length<1) return null;
  1290. var nowTime = timeStamp();
  1291. if (WM.likeQueue[0].timer<=nowTime) {
  1292. WM.console.likeQueueCounterNode.textContent = (WM.likeQueue.length-1);
  1293. var t=nowTime;
  1294. for (var i in WM.likeQueue) {
  1295. i.timer = t;
  1296. t+=(1000*WM.opts.autolikedelay);
  1297. }
  1298. return WM.likeQueue.shift(); // no longer returns the post, but the block of what to do with what post
  1299. }
  1300. return null;
  1301. },
  1302.  
  1303. processPosts : function(){
  1304. //dont run if menu is open or if requests are still out or if the console is paused
  1305. if($("Config") || (WM.requestsOpen >= WM.opts.maxrequests) || WM.paused) return;
  1306.  
  1307. var postNode=selectSingleNode(".//div[starts-with(@id,'post_') and contains(@class,'collect') and not(contains(@class,'paused') or contains(@class,'working'))]",{node:WM.console.feedNode});
  1308. if (postNode) {
  1309. var post = WM.posts[postNode.id.replace('post_','')];
  1310. if (post) post.open();
  1311. }
  1312. },
  1313.  
  1314. olderPosts : function (params) {
  1315. WM.fetch({older:true});
  1316. },
  1317.  
  1318. newerPosts : function (params) {
  1319. WM.fetch({newer:true});
  1320. },
  1321. fetchRange : function (params) {
  1322. WM.fetch({bypassPause:true, older:true, targetEdge:params.oldedge, currentEdge:params.newedge});
  1323. },
  1324.  
  1325. cleanPosts : function () {try{
  1326. for (var p in WM.posts) if (!WM.posts[p].isGhost) {
  1327. var post = WM.posts[p];
  1328. with (post) if (!(
  1329. isPinned || isCollect || isWorking ||
  1330. (isTimeout && !WM.opts.cleanTimedOut)
  1331. )) post.remove();
  1332. }
  1333. }catch(e){log("WM.cleanPosts(): "+e);}},
  1334. setIntervals : function() {try{
  1335. //setup the timer to try post collection
  1336. if (procIntv) window.clearInterval(procIntv);
  1337. procIntv=window.setInterval(WM.processPosts, 2000);
  1338.  
  1339. //setup the timer to get new posts
  1340. if (newIntv) window.clearInterval(newIntv);
  1341. if(calcTime(WM.opts.newinterval)>0) newIntv=window.setInterval(WM.newerPosts, calcTime(WM.opts.newinterval));
  1342.  
  1343. //setup the timer to get older posts
  1344. if (oldIntv) window.clearInterval(oldIntv);
  1345. if(calcTime(WM.opts.oldinterval)>0) oldIntv=window.setInterval(WM.olderPosts, calcTime(WM.opts.oldinterval)+2000);
  1346. olderLimit=calcTime(WM.opts.maxinterval)||0;
  1347.  
  1348. //setup the timer to clean up old posts from the feed
  1349. if (cleanIntv) window.clearInterval(cleanIntv);
  1350. if(calcTime(WM.opts.cleaninterval)>0) cleanIntv=window.setInterval(WM.cleanPosts, calcTime(WM.opts.cleaninterval)+250);
  1351.  
  1352. //setup global heartbeat
  1353. if (hbIntv) window.clearInterval(hbIntv);
  1354. hbIntv=window.setInterval(WM.onHeartbeat, WM.opts.heartRate);
  1355. }catch(e){log("WM.setIntervals: "+e);}},
  1356.  
  1357. hideCounters : function(){try{
  1358. hideNodes("//*[contains(@class,'accFailBlock')]");
  1359. }catch(e){log("WM.hideCounters: "+e);}},
  1360.  
  1361. showCounters : function(){try{
  1362. showNodes("//*[contains(@class,'accFailBlock')]");
  1363. }catch(e){log("WM.showCounters: "+e);}},
  1364.  
  1365. validatePost : function(fbPost){try{
  1366. //alert("validatepost");
  1367. //validate required post fields
  1368. /*if (!( exists(fbPost.application) && exists(fbPost.link) && fbPost.type=="link")) {
  1369. return;
  1370. }*/
  1371.  
  1372. //accept only posts we have sidekicks for
  1373. var app=WM.apps[fbPost.app_id];
  1374. //debug.print(app);
  1375. if (!exists(app)) return;
  1376. //debug.print("app detected");
  1377. //prevent redrawing same post in case one slips past the graph validator
  1378. var postID=fbPost.source_id + "_" + fbPost.post_id;
  1379. //debug.print([postID,fbPost.qid]);
  1380. if (WM.posts[postID]||null) {
  1381. //debug.print(WM.posts[postID].id);
  1382. return;
  1383. }
  1384. //debug.print("no duplicate post detected");
  1385. //fbPost.pageNode.className +=" notDuplicatePost";
  1386.  
  1387. //accept only posts for which a sidekick is enabled
  1388. if (!WM.quickOpts.masterSwitch[app.appID]) return;
  1389. //debug.print("sidekick for this app is ready and willing");
  1390.  
  1391. //create a Post object from the post data
  1392. var post=(WM.posts[postID]=new WM.Post(fbPost));
  1393. if (post) {
  1394. var hasID=post.identify();
  1395. WM.sortPosts(); //make sure new posts fit the current sort order and direction
  1396. if (hasID) {
  1397. WM.rulesManager.doEvent("onValidate",post);
  1398. WM.rulesManager.doEvent("onIdentify",post);
  1399. post.draw(true,true);
  1400. //debug.print("post has been told to draw");
  1401. //track the post
  1402. if (WM.opts.useFriendTracker && !post.isMyPost){
  1403. WM.friendTracker.track(post);
  1404. }
  1405. }
  1406. } else {
  1407. log("WM.validatePost: Unable to transform post data into a useful post object. (id:"+fbPost.source_id + "_" + fbPost.post_id+")");
  1408. }
  1409. }catch(e){log("WM.validatePost: "+e);}},
  1410.  
  1411. handleEdges : function(params){
  1412. /*
  1413. apps
  1414. friends
  1415. edge:{newer,older}
  1416. */
  1417. //console.log("handleEdges: "+JSON.stringify(params));
  1418. if (params.friends||null) {
  1419. //update user created feeds
  1420. for (var f=0,l=WM.feedManager.feeds.length;f<l;f++){
  1421. var feed = WM.feedManager.feeds[f];
  1422. //if this feed is listed in those passed back...
  1423. if (params.friends.contains(feed.id)){
  1424. //update each app filter in this feed
  1425. for (var c=0,l=params.apps.length;c<l;c++) {
  1426. var appID=params.apps[c];
  1427. filter = feed.filters["app_"+appID];
  1428. if (!(filter||null)) {
  1429. //this filter does not exist, create one
  1430. filter=feed.addFilter({id:"app_"+appID});
  1431. }
  1432. if (params.edge.older) filter.oldedge = params.edge.older;
  1433. if (params.edge.newer) filter.newedge = params.edge.newer;
  1434. filter.oldedgeNode.textContent = filter.oldedge;
  1435. filter.newedgeNode.textContent = filter.newedge;
  1436. if (timeStamp()-(filter.oldedge*1000)>olderLimit) filter.olderLimitReached=true;
  1437. }
  1438. }
  1439. }
  1440. } else {
  1441. //update base feed
  1442. feed = WM.feedManager.feeds[0];
  1443. for (var c=0,l=params.apps.length;c<l;c++) {
  1444. var appID=params.apps[c];
  1445. //update each app filter in this feed
  1446. filter = feed.filters["app_"+appID];
  1447. if (!(filter||null)) {
  1448. //this filter does not exist, create one
  1449. filter=feed.addFilter({id:"app_"+appID});
  1450. }
  1451. if (params.edge.older) filter.oldedge = params.edge.older;
  1452. if (params.edge.newer) filter.newedge = params.edge.newer;
  1453. filter.oldedgeNode.textContent = filter.oldedge;
  1454. filter.newedgeNode.textContent = filter.newedge;
  1455. if (timeStamp()-(filter.oldedge*1000)>olderLimit) filter.olderLimitReached=true;
  1456. }
  1457. }
  1458. },
  1459. fetch : function(params) {try{
  1460. return; //not used in version 4
  1461. /*
  1462. older:bool
  1463. newer:bool
  1464. apps:[]
  1465. feed:[]
  1466. targetEdge:unixtime
  1467. currentEdge:unixtime
  1468. bypassPause:bool
  1469. bypassFeedDisabled:bool
  1470. bypassAppDisabled:bool
  1471. */
  1472. params=params||{};
  1473. if (WM.fetchPaused && !params.bypassPause) return;
  1474.  
  1475. //convert a single passed app to a single entry list
  1476. if (exists(params.apps) && ((params.apps.objType||null)=="app")) {
  1477. var ret={};
  1478. ret[params.apps.appID]=params.apps;
  1479. params.apps=ret;
  1480. }
  1481. var useApps = params.apps||WM.apps;
  1482.  
  1483. //convert a single passed feed to an array
  1484. if (exists(params.feeds) && ((params.feeds.objType||null)=="feed")) {
  1485. params.feeds=[params.feeds];
  1486. }
  1487. params.currentEdge = params.currentEdge||null; //nullify undefined edge
  1488. //for each feed individually
  1489. var feeds=params.feeds||WM.feedManager.feeds;
  1490. for (var f=0,len=feeds.length;f<len;f++) {
  1491. var feed=feeds[f];
  1492. var friend=(feed.url!="https://graph.facebook.com/me/home")?[feed.id]:null;
  1493. //ignore the old me feed because it is a duplicate of the wall feed
  1494. if (feed.url!="https://graph.facebook.com/me/feed") if (feed.enabled || params.bypassFeedDisabled) {
  1495. //for each app make a separate fetch call for the given feed
  1496. //override this: no more by-app fetching
  1497. if (false && !WM.opts.groupFetching && (useApps||null)) {
  1498. for (var a in useApps) {
  1499. var app=useApps[a];
  1500. //only fetch for enabled apps
  1501. //where we are fetching new
  1502. //or if we are fetching old we are not at our older limit
  1503. var feedFilter=feed.filters["app_"+a];
  1504. if ((app.enabled || params.bypassAppDisabled) && (feedFilter.enabled || params.bypassFilterDisabled) && !(
  1505. params.older && feedFilter.olderLimitReached
  1506. )
  1507. ){
  1508. var G=Graph.fetchPostsFQL_B({
  1509. callback:WM.validatePost,
  1510. direction:(params.newer?1:(params.older?-1:0)),
  1511. limit:WM.opts.fetchQty,
  1512. targetEdge:(params.targetEdge||null), //special for new rules manager actions
  1513. friends:friend,
  1514. apps:[app.appID],
  1515. currentEdge:params.currentEdge||(params.newer?feedFilter.newedge:(params.older?feedFilter.oldedge:null)),
  1516. edgeHandler:WM.handleEdges,
  1517. noAppFiltering:WM.opts.noAppFiltering
  1518. });
  1519. }
  1520. }
  1521. //join apps together before fetching a single time for the given feed
  1522. } else {
  1523. //get the keys of the apps collection
  1524. var keys=Object.keys(useApps);
  1525. //if any sidekicks are docked
  1526. if (keys.length) {
  1527. //get the values of the apps collection
  1528. var appsToProcess=keys.map(function (key) {
  1529. return useApps[key];
  1530. //filter out which apps are able to be fetched for
  1531. }).filter(function(o,i,p){
  1532. //get the feed filter text
  1533. var feedFilter=feed.filters["app_"+o.appID];
  1534. //get if the app is enabled
  1535. var isEnabled = (o.enabled || params.bypassAppDisabled);
  1536. var isFilterEnabled=true,isOlderLimitReached=false;
  1537. if (feedFilter||null) {
  1538. //get if the feed filter is enabled
  1539. isFilterEnabled = (feedFilter.enabled || params.bypassFilterDisabled);
  1540. //get if the feed filter has already reached its older edge limit
  1541. isOlderLimitReached = (params.older && feedFilter.olderLimitReached);
  1542. } else {
  1543. //feed filter does not exist for this app
  1544. //assume it was deleted by the user on purpose
  1545. //and don't fetch for this app on this feed
  1546. log("WM.fetch: could not find filter for " + o.appID + "in feed " + feed.id);
  1547. return false;
  1548. }
  1549. if (isEnabled && isFilterEnabled && !isOlderLimitReached) return true;
  1550. return false;
  1551. //simply the array
  1552. }).map(function(o,i,p){
  1553. //just get the id's of apps to do, not the entire app object
  1554. return o.appID;
  1555. });
  1556. //make sure we matched filters to process
  1557. if (appsToProcess.length){
  1558. //get the shared edges of the passed apps
  1559. var edges = feed.getMergedEdges({apps:appsToProcess});
  1560. //console.log("getMergedEdges returned: "+JSON.stringify(edges));
  1561. var G=Graph.fetchPostsFQL_B({
  1562. callback:WM.validatePost,
  1563. direction:(params.newer?1:(params.older?-1:0)),
  1564. limit:WM.opts.fetchQty,
  1565. targetEdge:(params.targetEdge||null), //special for new rules manager actions
  1566. friends:friend,
  1567. apps:appsToProcess,
  1568. currentEdge:params.currentEdge||(params.newer?edges.newedge:(params.older?edges.oldedge:null)),
  1569. edgeHandler:WM.handleEdges,
  1570. noAppFiltering:WM.opts.noAppFiltering
  1571. });
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. }catch(e){log("WM.fetch: "+e);}},
  1578. changeDebugSettings : function(){try{
  1579. if (debug && debug.initialized) {
  1580. debug.doDebug = WM.opts.debug;
  1581. debug.debugLevel = parseInt(WM.opts.debugLevel);
  1582. debug.debugMaxComments = WM.opts.debugMaxComments;
  1583. debug.useScrollIntoView = WM.opts.debugScrollIntoView;
  1584. debug.stackRepeats = WM.opts.debugStackRepeats;
  1585. } else {
  1586. if (debug) debug.init();
  1587. setTimeout(WM.changeDebugSettings,1000);
  1588. }
  1589. }catch(e){log("WM.changeDebugSettings: "+e);}},
  1590. changeConfigSettings : function(){try{
  1591. WM.config.sectionsAsTabs=WM.opts.configSectionsAsTabs;
  1592. WM.config.separatorsAsTabs=WM.opts.configSeparatorsAsTabs;
  1593. WM.config.useScrollIntoView=WM.opts.configScrollIntoView;
  1594. WM.config.confirms={
  1595. save:WM.opts.configConfirmSave,
  1596. cancel:WM.opts.configConfirmCancel,
  1597. "import":WM.opts.configConfirmImport,
  1598. restore:WM.opts.configConfirmRestore
  1599. };
  1600. }catch(e){log("WM.changeConfigSettings: "+e);}},
  1601.  
  1602. resizeConsole : function(){try{
  1603. //negotiate height with fb bluebar
  1604. var node=$("pagelet_bluebar");
  1605. var h=(node)?elementOuterHeight(node):0;
  1606. with($("wmContent")){
  1607. style.height=document.documentElement.offsetHeight-h+"px";
  1608. style.width=document.documentElement.offsetWidth+"px";
  1609. }
  1610. WM.console.tabContainer.redraw();
  1611. WM.console.collectTabControl.redraw();
  1612.  
  1613. }catch(e){log("WM.resizeConsole: "+e);}},
  1614.  
  1615. setColors : function(){try{
  1616. var colors=["excluded","working","timeout","paused","nodef","failed","accepted","scam","pinned"];
  1617. var css="";
  1618. for (var c=0, color; (color=colors[c]); c++) {
  1619. css+=("div."+color+"{background-color:"+WM.opts["colors"+color]+" !important;}\n");
  1620. }
  1621. //set the new transition delay timer
  1622. css+=(".wm.post.short:hover .floater {-moz-transition-property: padding,border,width,height;-moz-transition-delay:"+WM.opts["transitiondelay"]+"s; width:240px; padding:5px 10px;border:1px solid;}\n");
  1623. remove($("user_colors_css"));
  1624. addGlobalStyle(css,"user_colors_css");
  1625. }catch(e){log("WM.setColors: "+e);}},
  1626.  
  1627. initConsole : function(){try{
  1628. WM.console.loading=false;
  1629. if (WM.console.initialized) log("WM Console Initialized");
  1630.  
  1631. //show options menu button
  1632. with (WM.console.configButton) {
  1633. className = className.removeWord("jsfHidden");
  1634. }
  1635.  
  1636. //set console heights
  1637. WM.resizeConsole();
  1638.  
  1639. //load feed sources
  1640. WM.feedManager.init();
  1641. //import friend tracker data
  1642. //and delete posts out of bounds with our "track for how many days"
  1643. WM.friendTracker.init();
  1644. WM.friendTracker.clean();
  1645.  
  1646. //initialize user colors
  1647. WM.setColors();
  1648. //set up the priorities and limits object
  1649. //and new rules manager
  1650. WM.rulesManager.init();
  1651.  
  1652. //decipher the dynamic tests
  1653. WM.grabber.init();
  1654.  
  1655. //show counters
  1656. if (WM.opts.showcounters) WM.showCounters(); else WM.hideCounters();
  1657. //set intervals
  1658. WM.setIntervals();
  1659. //set autopause
  1660. if (WM.opts.autopausecollect) WM.pauseCollecting(true);
  1661. if (WM.opts.autopausefetch) WM.pauseFetching(true);
  1662. //open a channel for sidekick communication
  1663. WM.fetchSidekickData();
  1664.  
  1665. //add an entrypoint for sidekicks since we know FB gave us access
  1666. var createDock = function(){
  1667. document.body.appendChild(
  1668. createElement('div',{id:'wmDock',style:'display:none;',onclick:function(){
  1669. WM.dock.answerDockingDoor();
  1670. }})
  1671. );
  1672. document.body.appendChild(
  1673. createElement('div',{id:'wmDataDump',style:'display:none;'})
  1674. );
  1675. };
  1676. createDock();
  1677.  
  1678. }catch(e){log("WM.initConsole: "+e);}},
  1679.  
  1680. cleanHistory : function(params){try{
  1681. log("Cleaning History");
  1682. params=params||{};
  1683. var ask=WM.opts.historyConfirmClean;
  1684. if (params.noConfirm || !ask || (ask && confirm("Clean and pack history for this profile?"))){
  1685. //history = getOptJSON("history_"+WM.currentUser.profile)||{};
  1686. var ageDays=parseInt(WM.opts.itemage);
  1687. var timeNow=timeStamp();
  1688. for(var i in WM.history) {
  1689. if( ( (timeNow-WM.history[i].date) /day) > ageDays) {
  1690. delete WM.history[i];
  1691. }
  1692. }
  1693. setOptJSON("history_"+WM.currentUser.profile, WM.history);
  1694. }
  1695. }catch(e){log("WM.cleanHistory: "+e);}},
  1696.  
  1697. optionsSetup : function(){try{
  1698. //debug.print("WM.optionsSetup:");
  1699. //create the settings tree
  1700. var configContent = {};
  1701. configContent.storageName="settings_"+(WM.quickOpts.useGlobalSettings?"global":WM.currentUser.profile);
  1702. configContent.onSave=WM.onSave;
  1703. configContent.title="FB Wall Manager "+WM.version+(WM.quickOpts.useGlobalSettings?" (!! Global Settings !!)":"");
  1704. configContent.logo=createElement("span",{}[
  1705. createElement("img",{className:"logo",src:"",textContent:"v"+WM.version}),
  1706. createElement("text","v"+WM.version)
  1707. ]);
  1708. configContent.css=WM.console.dynamicIcons()+jsForms.globalStyle();
  1709. //debug.print("starting settings section");
  1710. configContent.settings={}; o=configContent.settings;
  1711. o.btn_useGlobal={
  1712. type:"button",
  1713. label:"Use Global Settings",
  1714. title:"Switch to using a global storage for settings. Those settings can then be used by other accounts (not browser profiles).",
  1715. script:function(){
  1716. if (WM.quickOpts.useGlobalSettings||false) {
  1717. //already using global settings
  1718. return;
  1719. }
  1720. if (confirm("Switch to using global (shared) settings?")){
  1721. WM.quickOpts.useGlobalSettings=true;
  1722. WM.saveQuickOpts();
  1723. WM.config.title = "FB Wall Manager "+WM.version+" (!! Global Settings !!))";
  1724. WM.config.storageName = "settings_global";
  1725. WM.config.values=WM.config.read();
  1726. WM.config.configure();
  1727. WM.config.reload();
  1728. }
  1729. },
  1730. };
  1731. o.btn_useOwnProfile={
  1732. type:"button",
  1733. label:"Use Profile Settings",
  1734. title:"Switch to using your own profile storage for settings.",
  1735. script:function(){
  1736. if (!(WM.quickOpts.useGlobalSettings||false)) {
  1737. //already using profile settings
  1738. return;
  1739. }
  1740. if (confirm("Switch to using your own profile settings?")){
  1741. WM.quickOpts.useGlobalSettings=false;
  1742. WM.saveQuickOpts();
  1743. WM.config.title = "FB Wall Manager "+WM.version;
  1744. WM.config.storageName = "settings_"+WM.currentUser.profile;
  1745. WM.config.values=WM.config.read();
  1746. WM.config.configure();
  1747. WM.config.reload();
  1748. }
  1749. },
  1750. };
  1751. //debug.print("host options section start");
  1752. o.wmtab_opts=tabSection("Host Options",{
  1753. section_basicopts:section("Basics",{
  1754. /*authTokenTools:optionBlock("Authorization",{
  1755. devAuthToken:checkBox("Automatically check my developer tool app for my Auth Token"),
  1756. },true),*/
  1757. intervals:optionBlock("Post Fetching",{
  1758. newinterval:{
  1759. label:"Get Newer Posts Interval",
  1760. type:"selecttime",
  1761. title:"Fetch new posts from facebook after a set time.",
  1762. options:{
  1763. "off":"Off",
  1764. "tenth":"6 seconds",
  1765. "sixth":"10 seconds",
  1766. "half":"30 seconds",
  1767. "one":"1 minute",
  1768. "two":"2 minutes",
  1769. "three":"3 minutes",
  1770. "four":"4 minutes",
  1771. "five":"5 minutes",
  1772. "ten":"10 minutes",
  1773. },
  1774. "default":"t:30s"
  1775. },
  1776.  
  1777. fetchQty:{
  1778. label:"Fetch how many? (subject to filtering)",
  1779. type:"select",
  1780. title:"Posts fetched per request. Higher numbers affect speed of fetching.",
  1781. options:{
  1782. "5":"5",
  1783. "10":"10",
  1784. "25":"25",
  1785. "50":"50",
  1786. "100":"100",
  1787. "250":"250",
  1788. "500":"500 (FB maximum)", //known maximum fetch as of 9/8/2013
  1789. },
  1790. "default":"25"
  1791. },
  1792.  
  1793. oldinterval:{
  1794. label:"Get Older Posts Interval",
  1795. type:"selecttime",
  1796. title:"Fetch previous posts from facebook after a set time.",
  1797. options:{
  1798. "off":"Off",
  1799. "tenth":"6 seconds",
  1800. "sixth":"10 seconds",
  1801. "half":"30 seconds",
  1802. "one":"1 minute",
  1803. "two":"2 minutes",
  1804. "three":"3 minutes",
  1805. "four":"4 minutes",
  1806. "five":"5 minutes",
  1807. "ten":"10 minutes",
  1808. },
  1809. "default":"off"
  1810. },
  1811.  
  1812. maxinterval:{
  1813. label:"How old is too old?",
  1814. type:"selecttime",
  1815. title:"Tell WM what you think is a good max post age to fetch. Also affects which posts are considered 'stale'.",
  1816. options:{
  1817. "off":"Off/Infinite",
  1818. "hour":"1",
  1819. "2hour":"2",
  1820. "3hour":"3",
  1821. "4hour":"4",
  1822. "8hour":"8",
  1823. "12hour":"12",
  1824. "18hour":"18",
  1825. "24hour":"24",
  1826. "32hour":"32",
  1827. "48hour":"48",
  1828. },
  1829. "default":"t:1d"
  1830. },
  1831.  
  1832. //groupFetching:checkBox("All installed sidekicks in one request (default: one request per sidekick)",false,{},true),
  1833. //noAppFiltering:checkBox("Have WM filter posts for you instead of having facebook do it (may prevent some empty data set issues)",false,{},true),
  1834. },true),
  1835.  
  1836. autoPauseBlock:optionBlock("Fetching/Collecting Autopause",{
  1837. autopausefetch:checkBox("Pause Fetching after First Fetch"),
  1838. autopausecollect:checkBox("Pause Collection on Startup"),
  1839. },true),
  1840.  
  1841. multiTaskBlock:optionBlock("Multi-task",{
  1842. maxrequests:inputBox("Max requests simultaneously",1),
  1843. recycletabs:inputBox("Recycle Windows/Tabs",1),
  1844. recycletabsall:checkBox("Recycle All",true),
  1845. },true),
  1846.  
  1847. queBlock:optionBlock("Task-Queue",{
  1848. queuetabs:checkBox("Force all posts and autolikes through one tab using a queue (overrides multi-task)",true),
  1849. },true),
  1850.  
  1851. timeoutBlock:optionBlock("Time-outs",{
  1852. reqtimeout:inputBox("Item Acceptance Page Timeout (seconds)",30),
  1853. failontimeout:checkBox("Mark Timeout as Failure (default: retry indefinitely)"),
  1854. },true),
  1855. }),
  1856.  
  1857. section_access:section("Accessibility",{
  1858. shortModeBlock:optionBlock("Short Mode",{
  1859. thumbsize:{
  1860. label:"Thumbnail Size",
  1861. type:"select",
  1862. title:"Size of bonus thumbnails in display mode: short and .",
  1863. options:{
  1864. "mosquito":"16px",
  1865. "tiny":"24px",
  1866. "small":"32px",
  1867. "medium":"48px",
  1868. "large":"64px",
  1869. "xlarge":"96px",
  1870. },
  1871. "default":"medium"
  1872. },
  1873. transitiondelay:inputBox("Hover Box Delay (s)",1),
  1874. },true),
  1875.  
  1876. accessTweaksBlock:optionBlock("Tweaks",{
  1877. debugrecog:checkBox("Show Identified Text (instead of original link text)",true),
  1878. showcounters:checkBox("Show Accept/Fail Counts",true),
  1879. showdynamictips:checkBox("Show Dynamic Console Tips",true),
  1880. appsConfirmDeleteUDT:checkBox("Confirm Delete User Defined Types",true),
  1881. },true),
  1882.  
  1883. toolBoxBlock:optionBlock("Customize Post Toolbox",{
  1884. showtoolbox:checkBox("Enable ToolBox", true),
  1885.  
  1886. showopen:checkBox("Open Post",true),
  1887. showmarkfailed:checkBox("Mark As Failed",true),
  1888. showmarkaccepted:checkBox("Mark As Accepted",true),
  1889. showlike:checkBox("Like Post",true),
  1890. showreid:checkBox("Re-ID Post",true),
  1891. showmovetop:checkBox("Move to Top",true),
  1892. showmovebottom:checkBox("Move to Bottom",true),
  1893. showpin:checkBox("Pin Post",true),
  1894. showclean:checkBox("Clean Post",true),
  1895. showpostsrc:checkBox("Show Post Source",true),
  1896.  
  1897. //new stuff
  1898. showcancelprocess:checkBox("Cancel Process or Like",true),
  1899. showrestartprocess:checkBox("Restart Process or Like",true),
  1900. showpausetype:checkBox("Pause Bonus Type",true),
  1901. showunpausetype:checkBox("Unpause Bonus Type",true),
  1902. showaddfeed:checkBox("Add To Feeds",true),
  1903.  
  1904. showmakerule:checkBox("Rule From Post",true),
  1905. showoriginaldata:checkBox("Show Original Data",true),
  1906. showautocomment:checkBox("Auto Comment",true),
  1907. },true),
  1908. littleToolBoxBlock:optionBlock("Customize Mini Toolbox",{
  1909. littleButtonSize:{
  1910. label:"Mini Toolbutton Size (requires refresh to redraw)",
  1911. type:"select",
  1912. title:"Size of buttons on mini toolbars",
  1913. options:{
  1914. "16":"16px",
  1915. "24":"24px",
  1916. "32":"32px",
  1917. },
  1918. "default":"24",
  1919. },
  1920. },true),
  1921.  
  1922. userColorsBlock:optionBlock("Colors",{
  1923. colorsaccepted:colorBox("Accepted","limegreen"),
  1924. colorsfailed:colorBox("Failed","red"),
  1925. colorsworking:colorBox("Working","yellow"),
  1926. colorsexcluded:colorBox("Excluded","gray"),
  1927. colorspaused:colorBox("Paused","silver"),
  1928. colorsnodef:colorBox("No Definition","deepskyblue"),
  1929. colorsscam:colorBox("Potential Scam","purple"),
  1930. colorspinned:colorBox("Pinned","black"),
  1931. colorstimeout:colorBox("Timeout","orange"),
  1932. },true),
  1933.  
  1934. }),
  1935.  
  1936. section_feedback:section("Feedback",{
  1937. //publishwarning:{type:"message",title:"Autolike has changed",textContent:"As of WM beta 40 you must allow 'publish_actions' on the 'user data permissions' tab in your Graph API Explorer token builder.",newitem:true},
  1938. //gotoapiexplorer:anchor("Visit API Explorer","http://developers.facebook.com/tools/explorer?&version=v1.0"),
  1939. autoSetup:optionBlock("Setup",{
  1940. useautocomment:checkBox("Use Auto-comment (experimental)"),
  1941. useautolike:checkBox("Use Auto-like"),
  1942. //autoliketimeout:inputBox("Timeout (seconds)",30),
  1943. autolikedelay:inputBox("Ban-Prevention Delay (seconds)",3),
  1944. },true),
  1945. autoLikeBlock:optionBlock("Perform Feedback For",{
  1946. autolikeall:checkBox("All Posts"),
  1947. autolikeaccepted:checkBox("Accepted Posts"),
  1948. autolikesent:checkBox("Sent Posts"),
  1949. },true),
  1950. autoCommentListBlock:optionBlock("Comments (experimental)",{
  1951. autocommentlist:textArea("Random Comments (One per line)","Thanks\nThank you\nthanks"),
  1952. },true),
  1953. blockautolikebygame:optionBlock("Block Feedback by Game",{},false),
  1954. }),
  1955.  
  1956. section_filters:section("Filters",{
  1957. displayfilters:optionBlock("Remove Feed Parts (Classic Mode Only)",{
  1958. hideimages:checkBox("Images (All)"),
  1959. hideimagesunwanted:checkBox("Images (Unwanted Posts)"),
  1960. hidebody:checkBox("Post Body Text"),
  1961. hidevia:checkBox("Via App"),
  1962. hidedate:checkBox("Date/Time"),
  1963. },true),
  1964.  
  1965. filters:optionBlock("Hide By Type",{
  1966. hidemyposts:checkBox("My Posts"),
  1967. hideunwanted:checkBox("Unwanted"),
  1968. hideaccepted:checkBox("Accepted"),
  1969. hidefailed:checkBox("Failed"),
  1970. hidescams:checkBox("Scams"),
  1971. hidestale:checkBox("Stale Posts"),
  1972. hideexcluded:checkBox("Excluded"),
  1973. hideliked:checkBox("Liked By Me"),
  1974. hideunsupported:checkBox("Unsupported Apps"),
  1975.  
  1976. donthidewishlists:checkBox("Don't Hide Known Wish Lists"),
  1977. }),
  1978.  
  1979. //allow hiding all posts by particular games
  1980. filterapps:optionBlock("Hide By App",{}),
  1981.  
  1982. //now added dynamically as appID+"dontsteal"
  1983. dontstealBlock:optionBlock("Don't take W2W posts not for me",{}),
  1984.  
  1985. skipopts:optionBlock("Skip By Type",{
  1986. skipliked:checkBox("Liked By Me"),
  1987. skipstale:checkBox("Day-Old Posts"),
  1988. }),
  1989.  
  1990. filterTweaksBlock:optionBlock("Tweaks",{
  1991. accepton15:checkBox("Mark 'Unrecognized Response' As Accepted"),
  1992. markliked:checkBox("Mark Liked As Accepted (must check Skip Liked)"),
  1993. },true),
  1994.  
  1995. filterCleanupBlock:optionBlock("Cleanup",{
  1996. cleaninterval:{
  1997. label:"Cleanup Interval",
  1998. type:"selecttime",
  1999. title:"Remove unwanted posts from collection console after a set time.",
  2000. options:{
  2001. "off":"Off",
  2002. "one":"1 minute",
  2003. "two":"2 minutes",
  2004. "five":"5 minutes",
  2005. "ten":"10 minutes",
  2006. "fifteen":"15 minutes",
  2007. "thirty":"30 minutes",
  2008. "hour":"1 hour",
  2009. },
  2010. "default":"off"
  2011. },
  2012. cleanTimedOut:checkBox("Clean timed out posts",true),
  2013. },true),
  2014. }),
  2015.  
  2016. section_history:section("History",{
  2017. itemage:inputBox("How long to keep tried items in memory (days)",2),
  2018. oblock_historyConfirms:optionBlock("Confirm (Changes available on next config open)",{
  2019. historyConfirmClear:{type:"checkbox",label:"Clear History",title:"Confirm before clearing history.","default":true},
  2020. },true),
  2021. reset:button("Clear History",
  2022. WM.resetAccepted
  2023. ),
  2024. }),
  2025.  
  2026. section_feedopts:section("Feeds Manager",{
  2027. oblock_feedsConfirms:optionBlock("Confirm",{
  2028. feedsConfirmDeleteFeed:{type:"checkbox",label:"Delete Rule",title:"Require confirmation to delete a feed.","default":true},
  2029. },true),
  2030. }),
  2031.  
  2032. section_dynamicopts:section("Dynamic Grabber",{
  2033. dynamicopts:optionBlock("Dynamic Collection",{
  2034. dynamicFirst:checkBox("Run Dynamics BEFORE Sidekicks",true),
  2035. },true),
  2036. enableDynamic:optionBlock("Enable Dynamics by Game",{}),
  2037. oblock_dynamicConfirms:optionBlock("Confirm",{
  2038. dynamicConfirmDeleteTest:{type:"checkbox",label:"Delete Rule",title:"Require confirmation to delete a test.","default":true},
  2039. },true),
  2040. }),
  2041.  
  2042. section_friendtrackopts:section("Friend Tracker",{
  2043. useFriendTracker:checkBox("Enable Friend Tracking",true),
  2044. trackTime:inputBox("Track For How Many Days",2),
  2045. trackeropts:optionBlock("Track Data",{
  2046. trackCreated:checkBox("Post Creation Counts",true),
  2047. trackLastKnownPost:checkBox("Last Known Post Time",true),
  2048. trackAccepted:checkBox("Bonuses Accepted",true),
  2049. trackFailed:checkBox("Bonuses Failed",true),
  2050. },true),
  2051. oblock_trackerConfirms:optionBlock("Confirm",{
  2052. trackConfirmClearUser:{type:"checkbox",label:"Clear User Data",title:"Require confirmation to clear user data.","default":true},
  2053. },true),
  2054. }),
  2055. section_rulesopts:section("Rules Manager",{
  2056. oblock_rulesHeartbeat:optionBlock("Heartbeat",{
  2057. heartRate:inputBox("Global Heartbeat Delay (ms)",1000),
  2058. heartbeatAffectsApps:{type:"checkbox",label:"Affect Apps",title:"Heartbeat can be heard at app level on every rule at once. This can slow down your system."},
  2059. heartbeatAffectsPosts:{type:"checkbox",label:"Affect Posts",title:"Heartbeat can be heard at post level on every rule at once. This can slow down your system."},
  2060. heartbeatAffectsRules:{type:"checkbox",label:"Affect Rules",title:"Heartbeat can be heard at rule level on every rule at once. This can slow down your system."},
  2061. heartbeatAffectsFeeds:{type:"checkbox",label:"Affect Feeds",title:"Heartbeat can be heard at feed level on every rule at once. This can slow down your system."},
  2062. heartbeatAffectsFeedFilters:{type:"checkbox",label:"Affect Feed Filters",title:"Heartbeat can be heard at feed filter level on every rule at once. This can slow down your system."},
  2063. },true),
  2064. oblock_rulesConfirms:optionBlock("Confirm",{
  2065. rulesConfirmDeleteValidator:{type:"checkbox",label:"Delete Validator",title:"Require confirmation to delete a rule's validator.","default":true},
  2066. rulesConfirmDeleteAction:{type:"checkbox",label:"Delete Action",title:"Require confirmation to delete a rule's action.","default":true},
  2067. rulesConfirmDeleteRule:{type:"checkbox",label:"Delete Rule",title:"Require confirmation to delete a rule.","default":true},
  2068. rulesConfirmResetLimit:{type:"checkbox",label:"Reset Limit",title:"Require confirmation to reset individual limits.","default":true},
  2069. rulesConfirmResetAllLimits:{type:"checkbox",label:"Reset All Limits",title:"Require confirmation to reset all limits.","default":true},
  2070. rulesConfirmHatch:{type:"checkbox",label:"Hatch Eggs",title:"Require confirmation to hatch eggs.","default":true},
  2071. },true),
  2072. rulesJumpToNewRule:{type:"checkbox",label:"Jump To New Rules",title:"When new rules are created from tests or posts, select the rules manager tab and scroll the new rule into view.","default":true},
  2073. }),
  2074.  
  2075. section_dev:section("Debug",{
  2076. oblock_debugTweaks:optionBlock("Tweaks",{
  2077. pinundefined:checkBox("Pin Undefined Bonus Types"),
  2078. },true),
  2079. debugOpts:optionBlock("Debug",{
  2080. debug:checkBox("Enable Debug",true),
  2081. debugLevel:{
  2082. label:"Debug Sensitivity",
  2083. title:"Sets the level of errors and warnings to report. 0 is all, 5 shows only the worst.",
  2084. type:"select",
  2085. options:{
  2086. "0":"Function calls",
  2087. "1":"Function subsections & debug notes",
  2088. "2":"Captured expected errors",
  2089. "3":"Known open errors",
  2090. "4":"Unexpected errors",
  2091. "5":"Fatal errors",
  2092. },
  2093. "default":"0"
  2094. },
  2095. debugMaxComments:inputBox("Max debug lines (0 for no limit)",100),
  2096. debugScrollIntoView:checkBox("Use scrollIntoView"),
  2097. debugStackRepeats:checkBox("Stack Immediate Repeats"),
  2098.  
  2099. },true),
  2100. advDebugOpts:optionBlock("Advanced Debug",{
  2101. devDebugFunctionSubsections:checkBox("Debug Function Subsections",false),
  2102. devDebugGraphData:checkBox("Debug Graph Packets (not available for Chrome)",false),
  2103. },true),
  2104. GM_special:optionBlock("Script-runner Options",{
  2105. useGM_openInTab:checkBox("Use GM_openInTab instead of window.open",false),
  2106. },true),
  2107.  
  2108. }),
  2109.  
  2110. section_configopts:section("Config",{
  2111. oblock_configConfirms:optionBlock("Confirm (Changes available on next config open)",{
  2112. configConfirmSave:{type:"checkbox",label:"Save",title:"Confirm before saving settings.","default":true},
  2113. configConfirmCancel:{type:"checkbox",label:"Cancel",title:"Confirm before closing settings without saving.","default":true},
  2114. configConfirmImport:{type:"checkbox",label:"Import",title:"Confirm before importing settings.","default":true},
  2115. configConfirmRestore:{type:"checkbox",label:"Restore Defaults",title:"Confirm before restoring defaults.","default":true},
  2116. },true),
  2117. oblock_configStyling:optionBlock("Styling (Changes available on next config open)",{
  2118. configSectionsAsTabs:{type:"checkbox",label:"Display Sections as Tabs",title:"Converts top level roll-outs only. Display those rollouts as tabs on next open of config."},
  2119. configSeparatorsAsTabs:{type:"checkbox",label:"Display Separators as Tabs",title:"Converts second level roll-outs only. Display those rollouts as tabs on next open of config. Removes select all/none buttons on top of the separator."},
  2120. },true),
  2121. oblock_configTweaks:optionBlock("Tweaks (Changes available on next config open)",{
  2122. configScrollIntoView:{type:"checkbox",label:"Use scrollIntoView",title:"When tabs and sections are opened, use the scrollIntoView function to bring them more fully into view. This is jerky at best."},
  2123. },true),
  2124. }),
  2125. });
  2126.  
  2127. /*wmtab_games:tabSection("Sidekick Options",{
  2128. skmovedwarning:{type:"message",title:"Sidekick options have moved",textContent:"Sidekick options have been moved to separate config windows. Access them by using the 'Manage Sidekicks' tab, where you can find new 'Options' buttons for each sidekick."},
  2129. }),*/
  2130. //debug.print("info section start");
  2131. o.wmtab_info=tabSection("Info",{
  2132. MainMessageCenter:separator("Documentation - Messages - Help",null,{
  2133. //Mainupdate:anchor("Update Script","http://userscripts.org/scripts/source/86674.user.js"),
  2134. donateWM:{type:"link",label:"Donate for FBWM via Paypal",href:"https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=merricksdad%40gmail%2ecom&lc=US&item_name=Charlie%20Ewing&item_number=FBWM&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"},
  2135. Mainwikipage:anchor("Wiki Support Page","http://fbwm.wikia.com/wiki/Known_Issues"),
  2136. Mainsetupinfo:anchor("Setup Info","http://fbwm.wikia.com/wiki/New_User_Setup"),
  2137. Maindiscuss:anchor("Known Bugs","http://fbwm.wikia.com/wiki/Known_Issues"),
  2138. Mainrevisionlog:anchor("Revision Log","http://fbwm.wikia.com/wiki/Revisions"),
  2139. },true)
  2140. });
  2141. //debug.print("done config content");
  2142.  
  2143. //debug.print(configContent);
  2144. WM.config = new Config(configContent);
  2145. //debug.print("host options menu created");
  2146. // add options shortcut to user script commands
  2147. GM_registerMenuCommand("Wall Manager "+WM.version+" Options", function(){WM.config.open();});
  2148. }catch(e){log("WM.optionsSetup: "+e);}},
  2149.  
  2150. init : function(){try{
  2151. //capture user id/alias/name and make it global
  2152. WM.currentUser.id = Graph.userID;
  2153. WM.currentUser.alias = Graph.userAlias;
  2154. WM.currentUser.profile = WM.currentUser.id||WM.currentUser.alias; //switch to id over alias preference, as alias may change
  2155.  
  2156. debug.print("UserID:"+WM.currentUser.id+"; UserAlias:"+WM.currentUser.alias+"; WM is Using:"+WM.currentUser.profile);
  2157.  
  2158. //get WM.quickOpts
  2159. WM.quickOpts = getOptJSON('quickopts_'+WM.currentUser.profile)||{};
  2160. WM.quickOpts["filterApp"]=(WM.quickOpts["filterApp"]||"All");
  2161. WM.quickOpts["displayMode"]=(WM.quickOpts["displayMode"]||"0");
  2162. WM.quickOpts["masterSwitch"]=(WM.quickOpts["masterSwitch"]||{});
  2163. WM.quickOpts["useGlobalSettings"]=(WM.quickOpts["useGlobalSettings"]||false);
  2164.  
  2165. //create the options menu
  2166. //debug.print("starting options setup");
  2167. WM.optionsSetup();
  2168.  
  2169. //duplicate the options saved in WM.config
  2170. //debug.print("starting update settings values");
  2171. WM.updateSettingsValues();
  2172.  
  2173. //set up the config with its internal special variables
  2174. WM.changeConfigSettings();
  2175.  
  2176. //setup debug beyond its defaults
  2177. WM.changeDebugSettings();
  2178. //clean history
  2179. WM.history = getOptJSON('history_'+WM.currentUser.profile)||{};
  2180. WM.cleanHistory();
  2181. //prep the console now that we have an id and/or alias
  2182. //and then carry on with our init
  2183. WM.console.init({callback:WM.initConsole});
  2184. }catch(e){log("WM.init: "+e);}},
  2185. receiveSidekickMessage: function(event) {
  2186. if (isObject(event.data)) {
  2187. var data=event.data; //just shorten the typing
  2188. if (data.channel=="WallManager"){
  2189. //log(JSON.stringify(data));
  2190. //$("WM_debugWindow").childNodes[1].lastChild.scrollIntoView();
  2191. switch (data.msg){
  2192. case 2: //getting a comOpen response from sidekick
  2193. //WM.collector.tabs[data.tabID].comOpen=true;
  2194. break;
  2195. case 4: //getting a status package from sidekick
  2196. switch (data.params.action){
  2197. case "onFrameLoad":
  2198. WM.onFrameLoad(data.params);
  2199. break;
  2200. case "onFrameLoad3":
  2201. WM.onFrameLoad3(data.params);
  2202. break;
  2203. }
  2204. break;
  2205. }
  2206. }
  2207. }
  2208. },
  2209.  
  2210. run : function() {try{
  2211. // pre-load console images
  2212. //for(var img in imgs) try{new Image().src = imgs[img];}catch(e){log("preload: "+e);}
  2213.  
  2214. /* Removed for version 4
  2215.  
  2216. //special about:config entry for disabling storage of fb auth token
  2217. //should help multi account users
  2218. //if (getOpt("disableSaveAuthToken"))
  2219. Graph.authToken=null;
  2220. //patch 38 auth token stuff
  2221. var flagManualAuthSuccessful=getOpt("flagManualAuthSuccessful")||false;
  2222. if (WallManager.switches.manualAuthToken && !flagManualAuthSuccessful) {
  2223. var m="WM can no longer access your FB Access Token without your manual assistance.\nTo successfully fetch posts, please complete the following:\n\n*In a new browser window, visit: http://developers.facebook.com/tools/explorer\n\n*If required, allow that app access to your facebook information\n*Find the 'Get Access Token' button and click it\n*In the panel that appears, click 'extended permissions'\n*Be sure that 'read_stream' is selected or otherwise not blank\n*If you want to use autolike/autocomment also select 'publish_actions' from the 'user data permissions' tab*Click the 'Get Access Token' button\n*Now find the box that says 'Access Token' and select its value\n*Copy that value and paste it into the box on this promp\n\nNote: this token does not last forever, you may need to repeat this process";
  2224. var manualToken = prompt(m,"paste token here");
  2225. //validate manualToken at least somewhat
  2226. //halt if manual token is not given
  2227. if (manualToken=="" || manualToken==null || manualToken=="paste token here") {
  2228. alert("manual token not accepted, please refresh and try again");
  2229. return;
  2230. }
  2231. //pass the manual token along
  2232. Graph.authToken=manualToken;
  2233. //consider saving time by looking for auth tokens automatically from here out
  2234. var m = "WM thinks your auth token setup is successful.\nIf you like, I can make it so WM just checks your dev tool for new auth tokens every time.\n\nPress Cancel to continue entering auth codes manually.\n\n*If you have multiple facebook accounts on this computer using WM, please make sure you set up the API explorer with every account.";
  2235. var saveProgress = confirm(m);
  2236. if (saveProgress) {
  2237. setOpt("flagManualAuthSuccessful",true);
  2238. }
  2239. }
  2240.  
  2241. var G=Graph.fetchUser({callback:WM.init});
  2242. if (G){if (G.requestAlreadyOut) {
  2243. } else if (G.initRequestSlow) {
  2244. } else if (G.olderLimitReached) {
  2245. } else if (G.getAuthTokenFailed) {
  2246. }}
  2247. */
  2248. WM.init();
  2249. }catch(e){log("WM.run: "+e);}}
  2250.  
  2251. };
  2252.  
  2253. this.WM=WallManager;
  2254. //allow certain options to be seen outside of the WallManager object
  2255. //graph extension is external but still calls on WM options if they exist
  2256. this.opts=WM.opts;
  2257. this.quickOpts=WM.quickOpts;
  2258.  
  2259. })();