WM Post Object

This is the post class which is created under the WM version 4.x script

Acest script nu ar trebui instalat direct. Aceasta este o bibliotecă pentru alte scripturi care este inclusă prin directiva meta a // @require https://update.greatest.deepsurf.us/scripts/6894/27959/WM%20Post%20Object.js

  1. // ==UserScript==
  2. // @name WM Post Object
  3. // @namespace MerricksdadWMPostObject
  4. // @description This is the post class 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. //***************************************************************************************************************************************
  17. //***** Post Class
  18. //***************************************************************************************************************************************
  19. WM.Post = function(params){try{
  20. this.objType="post";
  21. var self=this;
  22. params=params||{};
  23.  
  24. //set defaults
  25. this.state=""; //classnames
  26. this.flags=0; //similar to classnames
  27. this.node=null; //collector panel node
  28. this.originalData=JSON.stringify(params); //clone the original data from facebook for viewing later
  29. //convert FQL data to what we have previously expected from graph api
  30. this.id=params.source_id + "_" + params.post_id;
  31. this.app=WM.apps[params.app_id];
  32. this.fromID=params.source_id;
  33. this.permalink="http://www.facebook.com/"+params.source_id+"/posts/"+params.post_id;
  34. this.fromName=params.fromName;
  35. this.date=params.created_time;
  36. this.message=params.message; //status message from post creator
  37. this.name=params.title; //params.attachment.name; //first line of the post
  38. this.title=params.title; //first line of the post
  39. this.caption=params.caption; //params.attachment.caption; //just below the title, a subtitle
  40. this.description=params.description; //params.attachment.description; //just below the caption, descriptive text about the story
  41. this.picture=params.picture; //params.app_data.images;
  42. this.likeLink = params.likeLink;
  43. this.pageNode = params.pageNode;
  44. this.commentLink = params.commentLink;
  45. this.commentNode = params.commentNode;
  46. //removed for WM 4
  47. /*try{
  48. this.picture = JSON.parse(this.picture)[0].fbml.match(/https?\:.+\.(png|gif|jpg)/)[0];
  49. } catch(e){
  50. //picture data match failed, no big deal
  51. //leave the data messed up because rules manager might still be able to use it
  52. }*/
  53. this.linkHref=params.linkHref;//||(params.action_links||null)?params.action_links[0].href:(params.attachment.media||null)?params.attachment.media[0].href:"";
  54. this.linkText=params.linkText;//||(params.action_links||null)?params.action_links[0].text:(params.attachment.media||null)?params.attachment.media[0].alt:"";
  55. this.targetID=params.target_id;
  56. //this.isLiked=params.isLiked; //params.like_info.user_likes;
  57. //convert a unix date to a readable date
  58. this.realtime=(new Date(this.date*1000).toLocaleString());
  59. //set a timer on the post for delayed deletion
  60. this.drawTime=timeStamp();
  61. this._isLiked=params.isLiked;
  62. this._isPinned=false;
  63. this._isPaused=false;
  64. this._isScam=false;
  65. this._isW2W=false;
  66. this._isForMe=false;
  67. this._isMyPost=false;
  68. this._isWishlist=false;
  69. this._isUndefined=false;
  70. this._status=0;
  71. this._isTimeout=false;
  72. this._isFailed=false;
  73. this._isAccepted=false;
  74. this._isExcluded=false;
  75. this._isStale=false;
  76. this._isCollect=false;
  77. this._isWorking=false;
  78. this._which=null;
  79. this._idText="";
  80. //use passed params
  81. //for (var p in params) this[p]=params[p];
  82.  
  83. //link to our application array of objects
  84. //this.app=WM.apps[this.application.id];
  85.  
  86. //shortcuts to app details
  87. this.__defineGetter__("synApp",function(){try{
  88. return this.app.synApp;
  89. }catch(e){log("WM.Post.synApp: "+e);}});
  90.  
  91. this.__defineGetter__("postedDay",function(){try{
  92. var d=new Date(this.date*1000);
  93. return d.getFullYear()+"/"+d.getMonth()+"/"+d.getDay();
  94. }catch(e){log("WM.Post.postedDay: "+e);}});
  95.  
  96. this.__defineGetter__("postedHour",function(){try{
  97. var d=new Date(this.date*1000);
  98. var h=d.getHours();
  99. var pm=(h/12)>1;
  100. return d.getFullYear()+"/"+d.getMonth()+"/"+d.getDay()+" "+((h>12)?h-12:h)+":00"+((pm)?"PM":"AM");
  101. }catch(e){log("WM.Post.postedHour: "+e);}});
  102.  
  103. this.__defineGetter__("appID",function(){try{
  104. return this.app.appID;
  105. }catch(e){log("WM.Post.appID: "+e);}});
  106.  
  107. this.__defineGetter__("appName",function(){try{
  108. return this.app.name;
  109. }catch(e){log("WM.Post.appName: "+e);}});
  110.  
  111. //get/set priority
  112. this.__defineGetter__("priority",function(){try{
  113. return this._priority;
  114. }catch(e){log("WM.Post.priority: "+e);}});
  115. this.__defineSetter__("priority",function(v){try{
  116. this._priority=v;
  117. }catch(e){log("WM.Post.priority: "+e);}});
  118.  
  119. //get/set liked status
  120. this.__defineGetter__("isLiked",function(){try{
  121. return this._isLiked;
  122. }catch(e){log("WM.Post.isLiked: "+e);}});
  123. this.__defineSetter__("isLiked",function(v){try{
  124. this._isLiked=v;
  125. //remove the toolbutton if liked
  126. if (this.node) with (this.node)
  127. className=className.toggleWordB(this._isLiked,"liked");
  128. if (this.likeButtonNode) with (this.likeButtonNode)
  129. className=className.toggleWordB(this._isLiked,"hidden");
  130. }catch(e){log("WM.Post.isLiked: "+e);}});
  131.  
  132. //identification flags
  133. this.__defineGetter__("isScam",function(){try{
  134. return this._isScam;
  135. }catch(e){log("WM.Post.isScam: "+e);}});
  136. this.__defineSetter__("isScam",function(v){try{
  137. this._isScam=v;
  138. if (this.node) with (this.node)
  139. className=className.toggleWordB(this._isScam,"scam");
  140. }catch(e){log("WM.Post.isScam: "+e);}});
  141.  
  142. this.__defineGetter__("isMyPost",function(){try{
  143. return this._isMyPost;
  144. }catch(e){log("WM.Post.isMyPost: "+e);}});
  145. this.__defineSetter__("isMyPost",function(v){try{
  146. this._isMyPost=v;
  147. if (this.node) with (this.node)
  148. className=className.toggleWordB(this._isMyPost,"isMyPost");
  149. }catch(e){log("WM.Post.isMyPost: "+e);}});
  150.  
  151. this.__defineGetter__("isW2W",function(){try{
  152. return this._isW2W;
  153. }catch(e){log("WM.Post.isW2W: "+e);}});
  154. this.__defineSetter__("isW2W",function(v){try{
  155. this._isW2W=v;
  156. if (this.node) with (this.node)
  157. className=className.toggleWordB(this._isW2W,"w2w");
  158. }catch(e){log("WM.Post.isW2W: "+e);}});
  159.  
  160. this.__defineGetter__("isForMe",function(){try{
  161. return this._isForMe;
  162. }catch(e){log("WM.Post.isForMe: "+e);}});
  163. this.__defineSetter__("isForMe",function(v){try{
  164. this._isForMe=v;
  165. if (this.node) with (this.node)
  166. className=className.toggleWordB(this._isForMe,"isForMe");
  167. }catch(e){log("WM.Post.isForMe: "+e);}});
  168.  
  169. this.__defineGetter__("isWishlist",function(){try{
  170. return this._isWishlist;
  171. }catch(e){log("WM.Post.isWishlist: "+e);}});
  172. this.__defineSetter__("isWishlist",function(v){try{
  173. this._isWishlist=v;
  174. if (this.node) with (this.node)
  175. className=className.toggleWordB(this._isWishlist,"wishlist");
  176. }catch(e){log("WM.Post.isWishlist: "+e);}});
  177.  
  178. this.__defineGetter__("isUndefined",function(){try{
  179. return this._isUndefined;
  180. }catch(e){log("WM.Post.isUndefined: "+e);}});
  181. this.__defineSetter__("isUndefined",function(v){try{
  182. this._isUndefined=v;
  183. if (this.node) with (this.node)
  184. className=className.toggleWordB(this._isUndefined,"noDef");
  185. }catch(e){log("WM.Post.isUndefined: "+e);}});
  186.  
  187. this.__defineGetter__("isStale",function(){try{
  188. return this._isStale;
  189. }catch(e){log("WM.Post.isStale: "+e);}});
  190. this.__defineSetter__("isStale",function(v){try{
  191. this._isStale=v;
  192. if (this.node) with (this.node)
  193. className=className.toggleWordB(this._isStale,"stale");
  194. }catch(e){log("WM.Post.isStale: "+e);}});
  195.  
  196. this.__defineGetter__("isTimeout",function(){try{
  197. return this._isTimeout;
  198. }catch(e){log("WM.Post.isTimeout: "+e);}});
  199. this.__defineSetter__("isTimeout",function(v){try{
  200. this._isTimeout=v;
  201. if (this.node) with (this.node)
  202. className=className.toggleWordB(this._isTimeout,"timeout");
  203. }catch(e){log("WM.Post.isTimeout: "+e);}});
  204.  
  205. this.__defineGetter__("isCollect",function(){try{
  206. return this._isCollect;
  207. }catch(e){log("WM.Post.isCollect: "+e);}});
  208. this.__defineSetter__("isCollect",function(v){try{
  209. this._isCollect=v;
  210. if (this.node) with (this.node)
  211. className=className.toggleWordB(this._isCollect,"collect");
  212. }catch(e){log("WM.Post.isCollect: "+e);}});
  213.  
  214. this.__defineGetter__("isExcluded",function(){try{
  215. return this._isExcluded;
  216. }catch(e){log("WM.Post.isExcluded: "+e);}});
  217. this.__defineSetter__("isExcluded",function(v){try{
  218. this._isExcluded=v;
  219. if (this.node) with (this.node)
  220. className=className.toggleWordB(this._isExcluded,"excluded");
  221. }catch(e){log("WM.Post.isExcluded: "+e);}});
  222.  
  223. this.__defineGetter__("isAccepted",function(){try{
  224. return this._isAccepted;
  225. }catch(e){log("WM.Post.isAccepted: "+e);}});
  226. this.__defineSetter__("isAccepted",function(v){try{
  227. this._isAccepted=v;
  228. if (this.node) with (this.node)
  229. className=className.toggleWordB(this._isAccepted,"accepted");
  230. }catch(e){log("WM.Post.isAccepted: "+e);}});
  231.  
  232. this.__defineGetter__("isFailed",function(){try{
  233. return this._isFailed;
  234. }catch(e){log("WM.Post.isFailed: "+e);}});
  235. this.__defineSetter__("isFailed",function(v){try{
  236. this._isFailed=v;
  237. if (this.node) with (this.node)
  238. className=className.toggleWordB(this._isFailed,"failed");
  239. }catch(e){log("WM.Post.isFailed: "+e);}});
  240.  
  241. this.__defineGetter__("isWorking",function(){try{
  242. return this._isWorking;
  243. }catch(e){log("WM.Post.isWorking: "+e);}});
  244. this.__defineSetter__("isWorking",function(v){try{
  245. this._isWorking=v;
  246. if (this.node) with (this.node)
  247. className=className.toggleWordB(this._isWorking,"working");
  248. }catch(e){log("WM.Post.isWorking: "+e);}});
  249.  
  250. this.__defineGetter__("isColored",function(){try{
  251. return this._isColored;
  252. }catch(e){log("WM.Post.isColored: "+e);}});
  253. this.__defineSetter__("isColored",function(v){try{
  254. this._isColored=v;
  255. if (this._isColored && this.colorOverride && this.node) this.node.style.setProperty("background-color",this.colorOverride,"important");
  256. }catch(e){log("WM.Post.isColored: "+e);}});
  257. //get/set post pinned
  258. this.__defineGetter__("isPinned",function(){try{
  259. return this._isPinned;
  260. }catch(e){log("WM.Post.isPinned: "+e);}});
  261. this.__defineSetter__("isPinned",function(v){try{
  262. this._isPinned=v;
  263. //rotate the pin icon
  264. var btnSize=WM.opts.littleButtonSize;
  265. if (this.pinImageNode) with (this.pinImageNode)
  266. className=className.swapWordB(this._isPinned,"pinned"+btnSize,"pin"+btnSize);
  267. //pinned class
  268. if (this.node) with (this.node)
  269. className=className.toggleWordB(this._isPinned,"pinned");
  270. }catch(e){log("WM.Post.isPinned: "+e);}});
  271.  
  272. //get/set post paused
  273. this.__defineGetter__("isPaused",function(){try{
  274. return this._isPaused;
  275. }catch(e){log("WM.Post.isPaused: "+e);}});
  276. this.__defineSetter__("isPaused",function(v){try{
  277. this._isPaused=v;
  278. if (this.node) with (this.node)
  279. className=className.toggleWordB(this._isPaused,"paused");
  280. }catch(e){log("WM.Post.isPaused: "+e);}});
  281.  
  282. //get/set status
  283. this.__defineGetter__("status",function(){try{
  284. return this._status;
  285. }catch(e){log("WM.Post.status: "+e);}});
  286. this.__defineSetter__("status",function(v){try{
  287. this._status=v;
  288. if (this.statusTextNode) this.statusTextNode.textContent=this._status;
  289. }catch(e){log("WM.Post.status: "+e);}});
  290.  
  291. //get/set idText
  292. this.__defineGetter__("idText",function(){try{
  293. return this._idText;
  294. }catch(e){log("WM.Post.idText: "+e);}});
  295. this.__defineSetter__("idText",function(v){try{
  296. this._idText=v;
  297. if (this.linkNode) this.linkNode.textContent=((this._idText||null) && WM.opts.debugrecog)?this._idText:this.linkText;
  298. }catch(e){log("WM.Post.idText: "+e);}});
  299. //get/set which bonus type this is
  300. this.__defineGetter__("which",function(){try{
  301. return this._which;
  302. }catch(e){log("WM.Post.which: "+e);}});
  303. this.__defineSetter__("which",function(v){try{
  304. this._which=v;
  305. if (this.whichTextNode) this.whichTextNode.textContent=this._which;
  306. }catch(e){log("WM.Post.which: "+e);}});
  307.  
  308. //check if in history already
  309. this.__defineGetter__("alreadyProcessed",function(){try{
  310. return exists(WM.history[this.id]);
  311. }catch(e){log("WM.Post.alreadyProcessed: "+e);}});
  312. /*
  313. //update the namespace parameter if it does not exist
  314. if (!exists(this.app.namespace)) this.app.namespace=this.application.namespace;
  315.  
  316. //validate the application namespace for sidekicks that provide namespace checking
  317. if (exists(this.app.namespace) && (this.app.namespace!=this.application.namespace)) {
  318. //Graph API namespace does not match sidekick known namespace, flag as scam
  319. this.isScam=true;
  320. }
  321.  
  322. //now drop the application object we got from FB
  323. if (exists(this.application)) delete this.application;
  324. */
  325. //this.fromID=this.from.id;
  326. //this.fromName=this.from.name;
  327. this.fromNameLastFirst=this.fromName;
  328. var sp=this.fromName.split(" ");
  329. if (isArray(sp) && sp.length>1) {
  330. this.fromNameLastFirst = sp.pop()+", "+sp.join(" ");
  331. }
  332.  
  333.  
  334. //(re)identify this post
  335. this.identify=function(params){try{
  336. params=params||{};
  337. //shortcuts
  338. var post=this;
  339. var app=post.app;
  340. var synApp=app.synApp;
  341. //set/reset priority, state, status & flags
  342. this.priority=50;
  343. this.status=0;
  344. this.state="";
  345. //prevent reset of some data holders
  346. if (!params.reid) {
  347. this.testData={};
  348. this.isLiked=false;
  349. this.isMyPost=false;
  350. this.isW2W=false;
  351. this.isForMe=false;
  352. this.isScam=false;
  353. }
  354. //reset data holders
  355. this.isStale=false;
  356. this.isCollect=false;
  357. this.isExcluded=false;
  358. this.isFailed=false;
  359. this.isAccepted=false;
  360. this.isPaused=false;
  361. this.isPinned=false;
  362. this.isUndefined=false;
  363. this.isWishlist=false;
  364. this.isTimeout=false;
  365. //avoid posts that belong to a disabled sidekick
  366. if(!WM.quickOpts.masterSwitch[app.appID]) {
  367. //master switch is off
  368. this.isExcluded=true;
  369. return true; //draw without identifying anything
  370. }
  371.  
  372. //hide posts by apps that we specifically told to hide
  373. if (WM.opts["hide"+app.appID]) {this.remove(); return false;}
  374.  
  375. //avoid potential scam posts
  376. /*if (WM.opts.scamblock) {
  377. if (!params.reid) {
  378. this.isScam=(!this.linkHref.match(new RegExp("^http(s):\/\/apps\.facebook\.com\/"+app.namespace))!=null);
  379. }
  380. if (this.isScam){
  381. this.isExcluded=true;
  382. if (WM.opts.hidescams) {this.remove(); return false;}
  383. }
  384. }*/
  385.  
  386. //avoid posts by self
  387. if (!params.reid) {
  388. var whoPosted = this.fromID;
  389. var whoName = this.fromName;
  390. this.isMyPost=(whoPosted==WM.currentUser.id);
  391. }
  392. if (this.isMyPost){
  393. this.isExcluded=true;
  394. if (WM.opts.hidemyposts) {this.remove(); return false;}
  395. }
  396.  
  397. //avoid W2W posts not for me
  398. if (!params.reid){
  399. this.isForMe = (this.targetID==WM.currentUser.id);
  400. this.isW2W = (this.targetID||null);
  401. }
  402. if (WM.opts[app.appID+"dontsteal"] && this.isW2W && !this.isForMe){
  403. this.isExcluded=true;
  404. if (WM.opts.hidenotforme) {this.remove(); return false;}
  405. }
  406.  
  407. //avoid posts older than olderLimit
  408. if (olderLimit!=0) {
  409. if (this.isStale=this.checkStale(olderLimit)){
  410. if (WM.opts.skipstale) this.isExcluded=true;
  411. if (WM.opts.hidestale) {this.remove(); return false;}
  412. }
  413. }
  414.  
  415. //get bonus type
  416. var w=(this.which = WM.which(this,{reid:params.reid}));
  417.  
  418. //check for exclude type
  419. if (w=="exclude") {
  420. this.isExcluded=true;
  421. }
  422.  
  423. //check for pause
  424. if(synApp.typesPaused.inArray(w)) this.isPaused=true;
  425. //check if undefined
  426. if (w=="none") {
  427. this.isUndefined=true;
  428. }
  429. if (w==synApp.appID+"doUnknown" || w==synApp.appID+"send") {
  430. this.isUndefined=true;
  431. }
  432.  
  433. //special pin undefined option
  434. if (WM.opts.pinundefined && this.isUndefined) this.isPinned=true;
  435.  
  436. //check if liked by me
  437. if (this.isLiked){
  438. if (WM.opts.skipliked){
  439. if (WM.opts.markliked) this.status=1; //mark liked as accepted
  440. this.isExcluded=true;
  441. debug.print("skip liked");
  442. }
  443. if (WM.opts.hideliked) {debug.print("hide liked");this.remove(); return false;}
  444. }
  445.  
  446. //check history
  447. this.status=this.status||0;
  448. if (this.alreadyProcessed) {
  449. //post previously processed
  450. this.status=(WM.history[this.id].status||0);
  451.  
  452. var gotItem=((this.status>0) || (this.status==-6) || (this.status==-4) || (this.status==-15 && WM.opts.accepton15));
  453. if (gotItem) {
  454. this.isAccepted=true;
  455. } else if (this.status<0) {
  456. this.isFailed=true;
  457. }
  458.  
  459. if (WM.opts.hideaccepted && gotItem) {this.remove(); return false;}
  460. if (WM.opts.hidefailed && this.status<0) {this.remove(); return false;}
  461. }
  462.  
  463. //check if excluded
  464. if (this.isExcluded && WM.opts.hideexcluded) {this.remove(); return false;}
  465.  
  466. //set identified text
  467. this.idText=WM.getAccText(synApp.appID,w,(this.alreadyProcessed),this.status);
  468.  
  469. //check if wanted
  470. this.isCollect=(!this.alreadyProcessed &&
  471. (w=="dynamic" || WM.apps[this.synApp.appID].opts[w] ||
  472. (w.startsWith("send") && WM.apps[this.synApp.appID].opts["sendall"])
  473. )
  474. );
  475.  
  476. //check if wishlist
  477. if (w.find("wishlist")) {
  478. this.isWishlist=true;
  479. if (WM.opts.hideunwanted && !WM.opts.donthidewishlists) {this.remove(); return false;}
  480. }
  481. //if unwanted
  482. if (!this.isCollect && WM.opts.hideunwanted) {this.remove(); return false;}
  483. //debug post
  484. /*var pkg=debug.print("WM.Post.debug: ");
  485. pkg.msg.appendChild(createElement("button",{type:"button",onclick:function(){
  486. //response.responseText.toClipboard();
  487. promptText(JSON.stringify(self));
  488. }},[
  489. createElement("img",{src:"http://i1181.photobucket.com/albums/x430/merricksdad/array.png",title:"Show Data",style:"width:16px;height:16px; vertical-align:bottom;"})
  490. ]));*/
  491. //return true to draw, false to hide
  492. return true;
  493. }catch(e){log("WM.Post.identify: "+e);}};
  494.  
  495. //open this post using the collector system
  496. this.open=function(params){try{
  497. params=params||{};
  498. var post = this;
  499. var id = this.id;
  500. var app = this.app;
  501. var synApp = this.synApp;
  502.  
  503. //perform the onBefore Collect event
  504. WM.rulesManager.doEvent("onBeforeCollect",post);
  505.  
  506. //fix the link based on sidekick alterlink information
  507. var alterLink=(synApp.alterLink||null);
  508. var targetHref = post.linkHref;
  509. var doAlterLink=(synApp.flags.alterLink||false);
  510. if (doAlterLink && alterLink) {
  511. //alert("doing alterlink...");
  512. //pack the alterlink into an array, or detect an array
  513. if (!isArray(alterLink)) alterLink=[alterLink];
  514. //iterate link alteration commands
  515. for (var alt=0,alteration;(alteration=alterLink[alt]);alt++) {
  516. //alert("making alteration...");
  517. //note that only find and replace functionality is available right now, no wildcards or array inserts will work
  518. var find = (alteration.find||"");
  519. alteration.dataSource=(alteration.dataSource||"either");
  520. //check if user is wanting a regex or string replacement
  521. if (alteration.isRegex||false) find=new RegExp(find,"");
  522. targetHref = targetHref.replace(find,(alteration.replace||""));
  523.  
  524.  
  525. //check for word specific changes
  526. if ((alteration.words||null) && (alteration.conversionChart||null)){
  527. //alert("inserting words...");
  528. //new alterlink capability to change data source from 'either' to another post part
  529. var dataSource = post.testData[alteration.dataSource].toLowerCase();
  530. //alert(dataSource);
  531. for (var w=0,len=alteration.words.length; w<len; w++) {
  532. var word=(alteration.words[w]).toLowerCase();
  533. if (dataSource.contains(word)) {
  534. //replace the word
  535. targetHref=targetHref.replace("{%1}",alteration.conversionChart[word.noSpaces()]);
  536. break;
  537. }
  538. }
  539. }
  540. }
  541. }
  542.  
  543. //fix the link, removing https and switching to http only
  544. targetHref = targetHref.replace('https://','http://');
  545.  
  546. //open the bonus page in a new tab or the previously opened tab object to save memory
  547. this.isWorking=true;
  548. post.state="working";
  549. WM.requestsOpen++;
  550. doAction(function(){WM.collector.open({url:targetHref,id:id,callback:(synApp.isVer3?WM.onFrameLoad3:WM.onFrameLoad),post:post,first:params.first||false,emergency:params.emergency||false});});
  551. }catch(e){log("WM.Post.open: "+e);}};
  552.  
  553. //open this post using the collector system even if already tried
  554. this.forceOpen=function(params){try{
  555. var post=self;
  556. this.isCollect=true;
  557. this.isFailed=false;
  558. this.isTimeout=false;
  559. this.isAccepted=false;
  560. post.open(params);
  561. }catch(e){log("WM.Post.forceOpen: "+e);}};
  562.  
  563. //like this post using the collector system
  564. this.like=function(){try{
  565. //var url=this.permalink;
  566. var self=this;
  567. //setTimeout(function(){WM.collector.open({url:url+"#likeit=true",id:url,callback:WM.onLikePost,post:self});},100);
  568. //Graph.likePost(this.id,{callback:WM.onLikePost,post:self});
  569. setTimeout(function(){Graph.likePost(self,{callback:WM.onLikePost,post:self});},100);
  570. }catch(e){log("WM.Post.like: "+e);}};
  571.  
  572. //comment on this post using the collector system
  573. this.comment=function(commentOverride){try{
  574. if (commentOverride=="") commentOverride = null;
  575. //not ready
  576. //confirm("Feature not ready");
  577. //return;
  578. //var url=this.permalink;
  579. var self=this;
  580. var say = commentOverride || WM.opts.autocommentlist.split("\n").pickRandom();
  581. //setTimeout(function(){WM.collector.open({url:url+"#commentit=true&say="+say,id:url,callback:WM.onLikePost,post:self});},100);
  582. log("commenting "+say);
  583. //Graph.commentPost(this.id,say);
  584. setTimeout(function(){Graph.commentPost(self,say);},100);
  585. }catch(e){log("WM.Post.comment: "+e);}};
  586.  
  587. //cancel collection in progress
  588. this.cancelProcess=function(){
  589. //tell the collector to cancel any processes with post equal this
  590. //this will cancel both collect and like activities
  591. WM.collector.cancelProcess({search:"post",find:this});
  592. this.processCancelled=true;
  593. },
  594.  
  595. //cancel collection in progress
  596. this.refreshProcess=function(){
  597. //tell the collector to reload the href on processes with post equal this
  598. //this will reload both collect and like activities
  599. WM.collector.refreshProcess({search:"post",find:this});
  600. this.processRestarted=true;
  601. },
  602.  
  603. //change the background color of this post
  604. this.setColor=function(color){try{
  605. this.colorOverride=color;
  606. this.isColored=(cBool(color));
  607. }catch(e){log("WM.Post.setColor: "+e);}};
  608. //change the bonus type of this post
  609. //and mark it for collection if needed
  610. //and update its idText
  611. this.setWhich=function(w){try{
  612. this.which=w;
  613. if ((w=="dynamic") || WM.apps[this.synApp.appID].opts[w] || (w.startsWith("send") && WM.apps[this.synApp.appID].opts["sendall"]) ) {
  614. this.isCollect=!this.alreadyProcessed;
  615. }
  616. //update the identified text
  617. this.idText=WM.getAccText(this.synApp.appID,w,(this.alreadyProcessed),this.status);
  618. }catch(e){log("WM.Post.setWhich: "+e);}};
  619. //get the time passed since this post was created
  620. this.__defineGetter__("age",function(){try{
  621. return timeStamp()-(this.date*1000);
  622. }catch(e){log("WM.Post.age: "+e);}});
  623.  
  624. this.__defineGetter__("whichText",function(){try{
  625. if (this.which=="dynamic") return "Dynamic Grab";
  626. return this.synApp.userDefinedTypes[this.which]||this.synApp.accText[this.which];
  627. }catch(e){log("WM.Post.whichText: "+e);}});
  628.  
  629. this.draw=function(redraw,reorder){try{
  630. var post=this;
  631. var app=post.app;
  632. var synApp=app.synApp;
  633. //clean old display
  634. if (this.node && redraw) {
  635. remove(this.node);
  636. this.node=null;
  637. }
  638.  
  639. //prefetch css words
  640. var tags=("")
  641. .toggleWordB(post.isAccepted,"accepted")
  642. .toggleWordB(post.isFailed,"failed")
  643. .toggleWordB(post.isTimeout,"timeout")
  644. .toggleWordB(post.isExcluded,"excluded")
  645. .toggleWordB(post.isStale,"stale")
  646. .toggleWordB(post.isCollect && !(post.isAccepted||post.isFailed),"collect")
  647. .toggleWordB(post.isWorking,"working")
  648. .toggleWordB(post.isW2W,"w2w")
  649. .toggleWordB(post.isForMe,"isForMe")
  650. .toggleWordB(post.isMyPost,"isMyPost")
  651. .toggleWordB(post.isColored,"colored")
  652. .toggleWordB(post.isPaused,"paused")
  653. .toggleWordB(post.isPinned,"pinned")
  654. .toggleWordB(post.isUndefined,"noDef")
  655. .toggleWordB(post.isWishlist,"wishlist")
  656. .toggleWordB(post.isScam,"scam")
  657. .toggleWordB(post.isLiked,"liked");
  658. //detect hidden/drawn image
  659. var hideimage = (WM.opts.hideimages || (WM.opts.hideimagesunwanted && (post.which==="none" || post.which==="exclude") ) );
  660. var fakeimage = hideimage && WM.quickOpts.displayMode!="0";
  661. hideimage=hideimage && WM.quickOpts.displayMode=="0";
  662. //shared elements
  663. if (redraw){
  664. post.toolboxNode=createElement("div",{className:"toolBox small inline"});
  665. post.imageNode=createElement("img",{className:((!fakeimage && post.picture)?"":"resourceIcon noImageSmall16"),src:((!fakeimage)?post.picture:""||""),onerror:function(){this.className=this.className+" resourceIcon noImageSmall16"}});
  666. post.imageLinkNode=(!hideimage)?
  667. createElement("span",{href:jsVoid,className:"picture",onclick:function(){post.forceOpen();} },[
  668. post.imageNode
  669. ]):null;
  670. post.floaterNode=null;
  671. post.bodyNode=null;
  672. post.actorNode=createElement("a",{className:"actor",textContent:post.fromName,href:"http://www.facebook.com/profile.php?id="+post.fromID});
  673. post.titleNode=createElement("span",{className:"title",textContent:post.name});
  674. post.captionNode=createElement("span",{className:"caption",textContent:post.caption});
  675. post.descriptionNode=createElement("span",{className:"description",textContent:post.description});
  676. post.dateNode=createElement("span",{className:"postDate",textContent:[post.date,post.realtime]});
  677. post.viaNode=createElement("a",{className:"appName",textContent:" via "+app.name,href:"http://apps.facebook.com/"+app.namespace+"/",title:app.appID});
  678. post.linkNode=createElement("a",{className:"linkText"+(post.isExcluded?" excluded":"")+(post.idText?" identified":""),textContent:((post.idText||null) && WM.opts.debugrecog)?post.idText:post.linkText,href:post.linkHref,title:post.linkText});
  679. post.statusNode=createElement("span",{className:"status",textContent:"Status: "+(post.status||"0")+ " " + (WM.statusText[post.status||"0"])});
  680. post.pausedNode=createElement("div",{className:"pausedHover",title:"Collection for this post is paused, click to reactivate.",onclick:function(){post.isPaused=false;}},[createElement("img",{className:"resourceIcon playRight64"})]);
  681. //create the layout
  682. switch (WM.quickOpts.displayMode||"0"){
  683.  
  684. case "0": //classic mode
  685. post.node=createElement("div",{id:"post_"+post.id,className:"wm post classic "+tags+((hideimage)?" noimage":""),title:(post.isScam?"Post is possible scam":"")},[
  686. post.toolboxNode,
  687. post.actorNode,
  688. post.imageLinkNode,
  689. (!WM.opts.hidebody)?post.bodyNode=createElement("div",{className:"body"},[
  690. post.titleNode,
  691. (post.caption||null)?post.captionNode:null,
  692. (post.description||null)?post.descriptionNode:null,
  693. ]):null,
  694. createElement("div",{style:"margin-top:5px;"},[
  695. (!WM.opts.hidedate)?post.dateNode:null,
  696. (!WM.opts.hidevia)?post.viaNode:null,
  697. post.linkNode,
  698. ]),
  699. post.pausedNode,
  700. ]);
  701. break;
  702.  
  703. case "1": case "3": //short mode and old priority mode
  704. post.node=createElement("div",{id:"post_"+post.id,className:"wm post short "+WM.opts.thumbsize+tags,title:(post.isScam?"Post is possible scam":"")},[
  705. post.imageLinkNode,
  706. post.floaterNode=createElement("div",{id:"floater_"+post.id,className:"floater "+WM.opts.thumbsize},[
  707. post.toolboxNode,
  708. post.actorNode,
  709. post.dateNode,
  710. post.viaNode,
  711. post.linkNode,
  712. post.statusNode,
  713. post.pausedNode,
  714. ]),
  715. ]);
  716. post.imageNode.onmousemove=WM.moveFloater;
  717. break;
  718.  
  719. case "2": //dev mode
  720. var fnLine=function(label,text){
  721. return createElement("div",{className:"line"},[
  722. createElement("label",{textContent:label+": "}),
  723. createElement("span",{textContent:text})
  724. ]);
  725. };
  726. post.node=createElement("div",{id:"post_"+post.id,className:"listItem wm post dev "+tags,title:(post.isScam?"Post is possible scam":"")},[
  727. post.idNode=fnLine("id", post.id),
  728. post.toolboxNode,
  729. //post.imageLinkNode,
  730. createElement("div",{className:"subsection"},(function(){
  731. var ret = [];
  732. ret.push(post.actorNode=fnLine("fromName (fromID)", post.fromName+"("+post.fromID+")"));
  733. ret.push(post.titleNode=fnLine("title",post.name));
  734. if (post.message||null)ret.push(post.messageNode=fnLine("msg",post.message));
  735. if (post.caption||null)ret.push(post.captionNode=fnLine("caption",post.caption));
  736. if (post.description||null)ret.push(post.descriptionNode=fnLine("desc",post.description));
  737. ret.push(post.appImageNode=fnLine("img",post.picture));
  738. ret.push(post.dateNode=fnLine("date",post.realtime));
  739. ret.push(post.appNameNode=fnLine("appName",app.name));
  740. ret.push(post.appIDNode=fnLine("appID",app.appID));
  741. ret.push(post.canvasNode=fnLine("canvas",app.namespace));
  742. ret.push(post.urlNode=fnLine("url",post.linkHref));
  743.  
  744. //show likes
  745. if (post.likes||null){
  746. if (post.likes.data||null){
  747. ret.push(fnLine("likes",""));
  748. ret.push(post.likesNode=createElement("div",{className:"subsection"},(function(){
  749. var data=post.likes.data;
  750. var retData=[];
  751. for(var d=0,lenL=data.length; d<lenL; d++){
  752. retData.push(fnLine("likeName(likeID)",data[d].name+"("+data[d].id+")"));
  753. }
  754. return retData;
  755. })()));
  756. }
  757. }
  758.  
  759. //show comments
  760. if (post.comments||null){
  761. if (post.comments.data||null){
  762. ret.push(fnLine("comments",""));
  763. ret.push(post.commentsNode=createElement("div",{className:"subsection"},(function(){
  764. var data=post.comments.data;
  765. var retData=[];
  766. for(var d=0,lenC=data.length; d<lenC; d++){
  767. retData.push(fnLine("commentorName(commentorID)",data[d].from.name+"("+data[d].from.id+")"));
  768. retData.push(fnLine("comment",data[d].message));
  769. }
  770. return retData;
  771. })()));
  772. }
  773. }
  774. ret.push(post.idTextNode=fnLine("idText",post.idText));
  775. ret.push(post.whichNode=fnLine("which",post.which));
  776. ret.push(post.linkTextNode=fnLine("linkText",post.linkText));
  777.  
  778. return ret;
  779. })() ),
  780. post.pausedNode
  781. ]);
  782. break;
  783. }
  784.  
  785. //add the toolbox
  786. post.addToolBox();
  787. //use color override
  788. if (post.colorOverride) {
  789. post.node.style.setProperty("background-color",post.colorOverride,"important");
  790. }
  791. }
  792.  
  793. //if a filter exists check against filter
  794. var filter=(WM.quickOpts.filterApp||"All");
  795. if (filter!="All" && filter!=app.appID) {
  796. //dont show this post in this filter
  797. if (this.node) remove(this.node);
  798. return;
  799. }
  800.  
  801. //insert the post into view by sort order
  802. if (redraw || reorder) {
  803. var groupBy=WM.quickOpts.groupBy;
  804. if (groupBy){
  805. //detect/create group
  806. var group=WM.newGroup({by:post[groupBy]});
  807. var sibling=post.nextSibling();
  808. if (sibling) group.insertBefore(post.node,sibling.node);
  809. else group.appendChild(post.node);
  810. } else {
  811. var sibling=post.nextSibling();
  812. if (sibling) WM.console.feedNode.insertBefore(post.node, sibling.node);
  813. else WM.console.feedNode.appendChild(post.node);
  814. }
  815. }
  816. }catch(e){log("WM.Post.draw: "+e);}};
  817.  
  818. this.openSource=function(){try{
  819. var url=this.permalink;
  820. //FF22 version
  821. GM_openInTab(url,"_blank");
  822. //FF21 version
  823. //((WM.opts.useGM_openInTab)?GM_openInTab:window.open)(url,"_blank");
  824. }catch(e){log("WM.Post.openSource: "+e);}};
  825.  
  826. this.addClass=function(s){try{
  827. if (this.node){
  828. this.node.className=this.node.className.addWord(s);
  829. }
  830. }catch(e){log("WM.Post.addWord: "+e);}};
  831.  
  832. this.removeClass=function(s){try{
  833. if (this.node){
  834. this.node.className=this.node.className.removeWord(s);
  835. }
  836. }catch(e){log("WM.Post.removeWord: "+e);}};
  837.  
  838. this.pause=function(){try{
  839. this.isPaused=true;
  840. }catch(e){log("WM.Post.pause: "+e);}};
  841.  
  842. this.unPause=function(){try{
  843. this.isPaused=false;
  844. }catch(e){log("WM.Post.unPause: "+e);}};
  845.  
  846. this.exclude=function(){try{
  847. this.isExcluded=true;
  848. }catch(e){log("WM.Post.exclude: "+e);}};
  849.  
  850. this.collect=function(){try{
  851. this.isCollect=true;
  852. }catch(e){log("WM.Post.collect: "+e);}};
  853.  
  854. this.stopCollect=function(){try{
  855. this.isCollect=false;
  856. }catch(e){log("WM.Post.collect: "+e);}};
  857.  
  858. this.togglePin=function(){try{
  859. this.isPinned=!this.isPinned;
  860. }catch(e){log("WM.Post.togglePin: "+e);}};
  861.  
  862. this.pin=function(){try{
  863. this.isPinned=true;
  864. }catch(e){log("WM.Post.pin: "+e);}};
  865.  
  866. this.unPin=function(){try{
  867. this.isPinned=false;
  868. }catch(e){log("WM.Post.unPin: "+e);}};
  869.  
  870. this.addToFeeds=function(){try{
  871. WM.feedManager.newFeed({id:this.fromID, title:this.fromName});
  872. WM.feedManager.save();
  873. }catch(e){log("WM.Post.addToFeeds: "+e);}};
  874.  
  875. this.accept=function(mark){try{
  876. this.isAccepted=true;
  877. this.isFailed=false;
  878. this.isTimeout=false;
  879. this.isWorking=false;
  880. this.isCollect=false;
  881. if (mark) WM.setAsAccepted(null, 3,this);
  882. }catch(e){log("WM.Post.accept: "+e);}};
  883.  
  884. this.fail=function(mark){try{
  885. this.isFailed=true;
  886. this.isAccepted=false;
  887. this.isTimeout=false;
  888. this.isWorking=false;
  889. this.isCollect=false;
  890. if (mark) WM.setAsFailed(null, -18,this);
  891. }catch(e){log("WM.Post.fail: "+e);}};
  892.  
  893. this.timeout=function(){try{
  894. this.isTimeout=true;
  895. this.isAccepted=false;
  896. this.isFailed=false;
  897. this.isWorking=false;
  898. this.isCollect=false;
  899. }catch(e){log("WM.Post.timeout: "+e);}};
  900.  
  901. this.remove=function(){try{
  902. var node=(this.node||$("post_"+this.id));
  903. if (node && node.parentNode) remove(node);
  904. this.node=null;
  905. //turn this post into a ghost so we can keep its data
  906. //for linked objects, but not process it in reid or redraw
  907. this.isGhost=true;
  908. //delete WM.posts[this.id];
  909. }catch(e){log("WM.Post.remove: "+e);}};
  910.  
  911. this.addToolBox=function(){try{
  912. var post=this;
  913. if (!WM.opts.showtoolbox) return;
  914. var toolNode = post.toolboxNode;
  915. if (toolNode) toolNode.appendChild(
  916. createElement("div",{},[
  917. createElement("div",{onclick:function(){post.forceOpen();},title:"Open Post",className:"littleButton oddBlue"+((!WM.opts.showopen)?" hidden":"")},[
  918. createElement("img",{className:"resourceIcon action"+WM.opts.littleButtonSize})]),
  919. createElement("div",{onclick:function(){post.cancelProcess();},title:"Cancel Process or AutoLike",className:"littleButton oddBlue"+((!WM.opts.showcancelprocess)?" hidden":"")},[
  920. createElement("img",{className:"resourceIcon cancelProcess"+WM.opts.littleButtonSize})]),
  921. createElement("div",{onclick:function(){post.refreshProcess();},title:"Restart Process or AutoLike",className:"littleButton oddBlue"+((!WM.opts.showrestartprocess)?" hidden":"")},[
  922. createElement("img",{className:"resourceIcon refreshProcess"+WM.opts.littleButtonSize})]),
  923. createElement("div",{onclick:function(){WM.pauseByType(post.app, post.which);},title:"Pause all bonuses of this type",className:"littleButton oddOrange"+((!WM.opts.showpausetype)?" hidden":"")},[
  924. createElement("img",{className:"resourceIcon stop"+WM.opts.littleButtonSize})]),
  925. createElement("div",{onclick:function(){WM.unPauseByType(post.app, post.which);},title:"Unpause all bonuses of this type",className:"littleButton oddGreen"+((!WM.opts.showunpausetype)?" hidden":"")},[
  926. createElement("img",{className:"resourceIcon playRight"+WM.opts.littleButtonSize})]),
  927. createElement("div",{onclick:function(){window.open(post.permalink,"_blank");},title:"Show Post Source",className:"littleButton oddBlue"+((!WM.opts.showpostsrc)?" hidden":"")},[
  928. createElement("img",{className:"resourceIcon openInNewWindow"+WM.opts.littleButtonSize})]),
  929. createElement("div",{onclick:function(){post.remove();},title:"Clean",className:"littleButton oddOrange"+((!WM.opts.showclean)?" hidden":"")},[
  930. createElement("img",{className:"resourceIcon trash"+WM.opts.littleButtonSize})]),
  931. createElement("div",{onclick:function(){post.togglePin();},title:"Pin",className:"littleButton"+((!WM.opts.showpin)?" hidden":"")},[
  932. post.pinImageNode=createElement("img",{className:"resourceIcon "+(post.isPinned?"pinned":"pin")+WM.opts.littleButtonSize})]),
  933. createElement("div",{onclick:function(){post.moveToBottom();},title:"Move to Bottom",className:"littleButton oddOrange"+((!WM.opts.showmovebottom)?" hidden":"")},[
  934. createElement("img",{className:"resourceIcon moveBottomLeft"+WM.opts.littleButtonSize})]),
  935. createElement("div",{onclick:function(){post.moveToTop();},title:"Move to Top",className:"littleButton oddGreen"+((!WM.opts.showmovetop)?" hidden":"")},[
  936. createElement("img",{className:"resourceIcon moveTopLeft"+WM.opts.littleButtonSize})]),
  937. createElement("div",{onclick:function(){post.reID();},title:"ReID Post",className:"littleButton"+((!WM.opts.showreid)?" hidden":"")},[
  938. createElement("img",{className:"resourceIcon identify"+WM.opts.littleButtonSize})]),
  939. createElement("div",{onclick:function(){post.addToFeeds();},title:"Add To Feeds",className:"littleButton"+((!WM.opts.showaddfeed)?" hidden":"")},[
  940. createElement("img",{className:"resourceIcon addFeed"+WM.opts.littleButtonSize})]),
  941. post.likeButtonNode=createElement("div",{onclick:function(){post.like();},title:"Like Post",className:"likeButton littleButton oddBlue"+(post.isLiked?" hidden":"")+((!WM.opts.showlike)?" hidden":"")},[
  942. createElement("img",{className:"resourceIcon like"+WM.opts.littleButtonSize})]),
  943. createElement("div",{onclick:function(){post.comment();},title:"Auto Comment",className:"littleButton oddBlue"+((!WM.opts.showautocomment)?" hidden":"")},[
  944. createElement("img",{className:"resourceIcon comment"+WM.opts.littleButtonSize})]),
  945. createElement("div",{onclick:function(){post.fail(true);},title:"Mark as Failed",className:"littleButton oddOrange"+((!WM.opts.showmarkfailed)?" hidden":"")},[
  946. createElement("img",{className:"resourceIcon minus"+WM.opts.littleButtonSize})]),
  947. createElement("div",{onclick:function(){post.accept(true);},title:"Mark as Accepted",className:"littleButton oddGreen"+((!WM.opts.showmarkaccepted)?" hidden":"")},[
  948. createElement("img",{className:"resourceIcon plus"+WM.opts.littleButtonSize})]),
  949. createElement("div",{onclick:function(){WM.rulesManager.ruleFromPost(post);},title:"Create Rule From Post",className:"littleButton oddBlue"+((!WM.opts.showmakerule)?" hidden":"")},[
  950. createElement("img",{className:"resourceIcon gotoLibrary"+WM.opts.littleButtonSize})]),
  951. createElement("div",{onclick:function(){promptText(self.originalData,true);},title:"Show Original Data",className:"littleButton"+((!WM.opts.showoriginaldata)?" hidden":"")},[
  952. createElement("img",{className:"resourceIcon object"+WM.opts.littleButtonSize})]),
  953. ])
  954. );
  955. }catch(e){log("WM.Post.addToolBox: "+e);}};
  956.  
  957. /*
  958. this.__defineGetter__("linkText", function(){try{
  959. if (this.actions.length >=3) return this.actions.last().name||"";
  960. else return "";
  961. }catch(e){log("WM.Post.linkText: "+e);}});
  962.  
  963. this.__defineGetter__("linkHref", function(){try{
  964. return this.link||((this.actions.length>=3)?(this.actions.last().link||""):"")||"";
  965.  
  966. if (this.actions.length >=3) return this.actions.last().link||"";
  967. else return this.link||"";
  968. }catch(e){log("WM.Post.linkHref: "+e);}});
  969. */
  970.  
  971. /*this.actionLink=function(action){try{
  972. //for (var a=0,act;(act=this.actions[a]);a++) if (act.name.toLowerCase()==action.toLowerCase()) {return act.link; break;}
  973. return this.linkHref;
  974. }catch(e){log("WM.Post.actionLink: "+e);}};*/
  975.  
  976. this.__defineGetter__("body", function(){try{
  977. return (this.title||"")+" "+(this.caption||"")+" "+(this.description||"");
  978. }catch(e){log("WM.Post.body: "+e);}});
  979.  
  980. this.__defineGetter__("either", function(){try{
  981. return this.linkText+" "+this.body;
  982. }catch(e){log("WM.Post.either: "+e);}});
  983.  
  984. /*this.__defineGetter__("date", function(){try{
  985. return this["created_time"];
  986. }catch(e){log("WM.Post.date: "+e);}});*/
  987.  
  988. this.checkStale=function(timeOverride) {try{
  989. if (exists(timeOverride) && timeOverride==0) return false;
  990. var now = timeStamp();
  991. var pubTime = this.date*1000; //(this.date.length < 10)?this.date+"000":this.date;
  992. //var pubTime = this.date+"000";
  993. var aDay = (1000 * 60 * 60 * 24);
  994. return (now-pubTime)>(timeOverride||aDay);
  995. }catch(e){log("WM.Post.checkStale: "+e);}};
  996.  
  997. //req must equal "id" or "name"
  998. /*this.getTargets=function(req){try{
  999. req = req||"id";
  1000. var ret = [];
  1001. if (exists(this.to)) {
  1002. for (var i=0,target; (target=this.to.data[i]);i++) ret.push(target[req]);
  1003. }
  1004. return ret;
  1005. }catch(e){log("WM.Post.getTargets: "+e);}};*/
  1006.  
  1007. //ret must equal "id" or "message" or "name" or "count"
  1008. this.getComments=function(req){try{
  1009. var ret = [];
  1010. if (exists(this.comments)) if (this.comments.count) {
  1011. switch(req){
  1012. case "message": for (var i=0,comment; (comment=this.comments.data[i]);i++) ret.push(comment[req]); break;
  1013. case "id":case "name": for (var i=0,comment; (comment=this.comments.data[i]);i++) ret.push(comment.from[req]); break;
  1014. case "count": return this.comments.count; break;
  1015. }
  1016. }
  1017. return ret;
  1018. }catch(e){log("WM.Post.getComments: "+e);}};
  1019.  
  1020. //ret must equal "id" or "name" or "count"
  1021. this.getLikes=function(req){try{
  1022. req = req||"id";
  1023. var ret = [];
  1024. if (exists(this.likes)) if (this.likes.count) {
  1025. switch(req){
  1026. case "id":case "name": for (var i=0,like; (like=this.likes.data[i]); i++) ret.push(like[req]); break;
  1027. case "count": return this.likes.count; break;
  1028. }
  1029. }
  1030. return ret;
  1031. }catch(e){log("WM.Post.getLikes: "+e);}};
  1032.  
  1033. this.moveToTop = function(){try{
  1034. if (this.node||null) this.node.parentNode.insertBefore(this.node,this.node.parentNode.childNodes[0]);
  1035. }catch(e){log("WM.Post.moveToTop: "+e);}};
  1036.  
  1037. this.moveToBottom = function(){try{
  1038. if (this.node||null) this.node.parentNode.appendChild(this.node);
  1039. }catch(e){log("WM.Post.moveToBottom: "+e);}};
  1040.  
  1041. this.setPriority = function(value){try{
  1042. this.priority=value;
  1043. remove(this.node);
  1044. this.draw();
  1045. }catch(e){log("WM.Post.setPriority: "+e);}};
  1046. this.reID = function(params){try{
  1047. params=params||{};
  1048. //reidentify
  1049. var oldW=this.which;
  1050. if (this.identify({reid:true})) {
  1051. WM.rulesManager.doEvent("onIdentify",this);
  1052. }
  1053. //sort me into proper location
  1054. WM.sortPosts();
  1055.  
  1056. //redraw||reorder
  1057. if (!this.isGhost) {
  1058. this.draw(true,true);
  1059. }
  1060. }catch(e){log("WM.Post.reID: "+e);}};
  1061.  
  1062. //return the next visible sibling post
  1063. //now checks for group and visibility
  1064. this.nextSibling = function(){try{
  1065. //determine if there is an app filter
  1066. var filter=(WM.quickOpts.filterApp||"All");
  1067. //determine display grouping
  1068. var groupBy=WM.quickOpts.groupBy;
  1069. var group=(groupBy)?WM.newGroup({by:this[groupBy]}):null;
  1070. //get visible posts
  1071. var visiblePosts=(filter=="All")?WM.posts:matchByParam(WM.posts,"appID",filter);
  1072. if (groupBy) visiblePosts=matchByParam(visiblePosts,groupBy,this[groupBy]);
  1073. //search for the current post
  1074. var found=false, sibling=null;
  1075. for (var p in visiblePosts) {
  1076. if (found && visiblePosts[p].node) {
  1077. if ((!groupBy && visiblePosts[p].node.parentNode==WM.console.feedNode)
  1078. || (groupBy && visiblePosts[p].node.parentNode==group)){
  1079. sibling=visiblePosts[p];
  1080. break
  1081. }
  1082. } else if (visiblePosts[p]==this) found=true;
  1083. }
  1084.  
  1085. //return what is found
  1086. return sibling;
  1087. //warning: returns null if this is the last visible post
  1088. }catch(e){log("WM.Post.nextSibling: "+e);}};
  1089.  
  1090. //return the previous visible sibling post
  1091. //now checks for group and visibility
  1092. this.previousSibling = function(){try{
  1093. //determine if there is an app filter
  1094. var filter=(WM.quickOpts.filterApp||"All");
  1095. //determine display grouping
  1096. var groupBy=WM.quickOpts.groupBy;
  1097. var group=(groupBy)?WM.newGroup({by:this[groupBy]}):null;
  1098.  
  1099. //get visible posts
  1100. var visiblePosts=(filter=="All")?WM.posts:matchByParam(WM.posts,"appID",filter);
  1101. if (groupBy) visiblePosts=matchByParam(visiblePosts,groupBy,this[groupBy]);
  1102. //search for the current post
  1103. var sibling=null;
  1104. for (var p in visiblePosts) {
  1105. if (visiblePosts[p]==this) break;
  1106. else if (visiblePosts[p].node) {
  1107. if ((!groupBy && visiblePosts[p].node.parentNode==WM.console.feedNode)
  1108. || (groupBy && visiblePosts.node.parentNode==group)){
  1109. sibling=visiblePosts[p];
  1110. }
  1111. }
  1112. }
  1113. //return what is found
  1114. return sibling;
  1115. //warning: returns null if this is the first visible post
  1116. }catch(e){log("WM.Post.previousSibling: "+e);}};
  1117.  
  1118.  
  1119. //get the friend object related with this post (from the friend tracker)
  1120. this.__defineGetter__("relatedFriend",function(){try{
  1121. return WM.friendTracker.friends[this.fromID]||null;
  1122. }catch(e){log("WM.Post.relatedFriend: "+e);}});
  1123. this.__defineGetter__("friendAcceptedCount",function(){try{
  1124. return this.relatedFriend.acceptCount;
  1125. }catch(e){log("WM.Post.friendAcceptedCount: "+e);}});
  1126.  
  1127. this.__defineGetter__("friendFailedCount",function(){try{
  1128. return this.relatedFriend.failCount;
  1129. }catch(e){log("WM.Post.friendFailedCount: "+e);}});
  1130.  
  1131. //a little cleanup
  1132. params = null;
  1133. }catch(e){log("WM.Post.init: "+e);}};
  1134.  
  1135.  
  1136. })();