WM Post Object

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

当前为 2014-12-11 提交的版本,查看 最新版本

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