Advertisement
ntamas

Komment expander LOL

Sep 9th, 2022
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:(function(){let%20todo=6;const%20EXPAND_POST=1;const%20EXPAND_COMMENTS=2;const%20EXPAND_REPLIES=4;const%20EXPAND_XLAT=8;const%20EXPAND_FILTER=16;const%20WAIT_TIME=100;const%20MAX_WAIT=20;const%20END_DELAY=2.5;const%20POST_ARTICLE="[class=\"lzcic4wl\"][role=\"article\"]";const%20VIDEO_ARTICLE="._6x84,[data-pagelet=\"TahoeRightRail\"]";const%20FS_ARTICLE=".o36gj0jk:not([role=\"navigation\"]),[role=\"complementary\"]";const%20NEW_ARTICLE=POST_ARTICLE+","+FS_ARTICLE+","+VIDEO_ARTICLE;const%20POST_ACTION=".sjgh65i0%20>%20div%20>%20div%20>%20div%20>%20div%20>%20div%20>%20span,.jifvfom9[role=\"button\"],.p24jkzn5,.sjgh65i0%20>%20div%20>%20div%20>%20div%20>%20div%20>%20div%20>%20a%20>%20div";const%20POST_ROOT=".userContentWrapper,.uiScrollableAreaContent,"+NEW_ARTICLE;const%20RESPONSE_COUNTER="[aria-label][role=\"article\"]";const%20CLASSIC_GET_CONTENT="._4sxc";const%20CLASSIC_GET_REPLIES="._4sso";const%20NEW_GET_CONTENT=".fv0vnmcu%20>%20.lrazzd5p";const%20NEW_GET_COMMENTS=".bkfpd7mw%20.jklb3kyz%20.lrazzd5p";const%20SHOW_COMMENTS="[data-ft=\u0027{\"tn\":\"O\"}\u0027]";const%20SINGLE_COMMENT_AREA="._3w53,._6iiv,._7a9a";const%20FILTER_ROOT=POST_ROOT+",.uiScrollableAreaContent,.uiStreamStory";const%20FILTER_DONE="h6%20~%20ul%20>%20li";const%20FILTER_ATTR="data-ordering";const%20FILTER_VALUE="RANKED_UNFILTERED";const%20FILTER_NEW=".bp9cbjyn%20>%20.p8dawk7l[role=\"button\"]:not([aria-label]):not([aria-haspopup]):not(.jifvfom9):not(._4sxc)";const%20CSS_LOGIN_STUFF="._5hn6,%20._67m7,%20.generic_dialog_modal,%20.rlt63pii";const%20BASE_SEE_MORE=".text_exposed_link%20.see_more_link_inner";const%20EXPOSE_CONTENT=".text_exposed_link";const%20CSS_SEE_MORE=".fss:not(._5shl)";const%20SMN=".lrazzd5p[role=\"button\"]:not(.m5l1wtfr)";const%20SEE_MORE_NEW=POST_ARTICLE+"%20"+SMN+","+FS_ARTICLE+"%20"+SMN+","+VIDEO_ARTICLE+"%20"+SMN;const%20_NONE="no-value";const%20_COMMENTS="-comments";const%20_REPLIES="-replies";const%20SETTINGS_KEY="expand-all-todo";function%20bind(obj,fn){return%20function(){fn.apply(obj,arguments);};}let%20Global=null;if(!document.querySelectorAll("xx").forEach){Object.prototype.forEach=function(callback){let%20T;if(arguments.length>1){T=arguments[1];}let%20O=Object(this);let%20len=O.length>>>0;let%20k=0;while(k<len){if(k%20in%20O){callback.call(T,O[k],k,O);}k++;}};}class%20EscHandler{constructor(){this.abortNow=false;this.handler=bind(this,this.docKeyDown);}shouldAbort(){return%20this.abortNow;}abort(value){if(value&&!this.shouldAbort()&&!Global.cfg){Global.log("Aborting...");}this.abortNow=value;}on(){this.abortNow=false;document.addEventListener("keydown",this.handler);}off(){this.abortNow=true;document.removeEventListener("keydown",this.handler);}docKeyDown(e){if(e.keyCode==27){e.preventDefault();this.abort(true);if(Global.cfg){Session.trulyEnd();}}}}class%20CfgHandler{constructor(){this.doConfig=false;this.handler=bind(this,this.docKeyDown);}shouldConfig(){return%20this.doConfig;}on(){this.doConfig=false;document.addEventListener("keydown",this.handler);}off(){this.doConfig=true;document.removeEventListener("keydown",this.handler);}docKeyDown(e){if(e.keyCode==="S".charCodeAt(0)){e.preventDefault();if(e.ctrlKey){Settings.removeKey(SETTINGS_KEY);Global.log("Will%20use%20default%20settings");return;}this.doConfig=true;if(Global.ending){CfgWindow.showIt();}}}}class%20Settings{static%20hasValue(value){return%20window.localStorage.getItem(value)!==null;}static%20getValue(value,deflt){if(arguments.length<2){deflt=null;}if(!Settings.hasValue(value)){return%20deflt;}return%20window.localStorage.getItem(value);}static%20getInt(value,deflt){if(arguments.length<2){deflt=-1;}return%20Number.parseInt(Settings.getValue(value,deflt),10);}static%20getBoolean(value,deflt){if(arguments.length<2){deflt="false";}return%20Settings.getValue(value,""+deflt)=="true";}static%20setValue(key,value){return%20window.localStorage.setItem(key,""+value);}static%20removeKey(key){return%20window.localStorage.removeItem(key);}}class%20BaseWindow{constructor(){this.id="base-window";}show(){const%20WANT_W=300;const%20WANT_H=200;const%20sizer=document.querySelector("html");const%20w=sizer.clientWidth;const%20h=sizer.clientHeight;let%20x=0;if(w>WANT_W){x=(w-WANT_W)/2;}let%20y=0;if(h>WANT_H){y=(h-WANT_H)/3;}let%20div=document.createElement("div");div.id=this.id;div.style.direction="ltr";div.style.position="fixed";div.style.zIndex="999999";div.style.left=x+"px";div.style.width=WANT_W+"px";div.style.top=y+"px";div.style.height=WANT_H+"px";div.style.color="#fff";div.style.backgroundColor="#425f9c";document.body.insertAdjacentElement("afterbegin",div);this.create(div);this.init(div);}create(div){}init(div){}hide(){document.querySelectorAll("#"+this.id).forEach(item=>document.body.removeChild(item));}}class%20CfgWindow%20extends%20BaseWindow{constructor(){super();this.id="cfg-window";}create(div){let%20node=document.createElement("p");div.appendChild(node);node.innerHTML="<i>Expand%20All</i>%20Settings";node.style.marginLeft="4px";node.style.fontWeight="bold";const%20boxes=[["In%20Classic%20Facebook,%20click%20<i>Continue%20Reading</i>%20links.",EXPAND_POST],["Expand%20comments.",EXPAND_COMMENTS],["Expand%20replies.",EXPAND_REPLIES],["Don't%20force%20<i>All%20comments</i>%20filter.",EXPAND_FILTER]];boxes.forEach(item=>{node=document.createElement("p");div.appendChild(node);node.style.marginTop="2px";node.style.marginBottom="2px";let%20node2=document.createElement("input");node.appendChild(node2);node2.type="checkbox";node2.value=item[1];node2.style.marginLeft="15px";node2.style.cursor="pointer";node2=document.createElement("label");node.appendChild(node2);node2.innerHTML=item[0];node2.style.cursor="pointer";node2.style.paddingBottom="5px";node2.style.fontWeight="normal";node2.style.color="#fff";});node=document.createElement("div");div.appendChild(node);node.style.textAlign="center";let%20node2=document.createElement("button");node.appendChild(node2);node2.innerHTML="Done";node2.style.cursor="pointer";node2.addEventListener("click",Session.trulyEnd);div.addEventListener("CheckboxStateChange",CfgWindow.check);div.addEventListener("click",CfgWindow.check);}static%20check(e){let%20node=Dom.upThenDown(e.target,"p","input");if(!!node&&node!=e.target){node.checked=!node.checked;if(node.checked){todo|=Number.parseInt(node.value);}else{todo&=~Number.parseInt(node.value);}Settings.setValue(SETTINGS_KEY,todo);}}init(div){let%20boxes=div.querySelectorAll("input");if(boxes.length===4){boxes[0].checked=(todo&EXPAND_POST)!=0;boxes[1].checked=(todo&EXPAND_COMMENTS)!=0;boxes[2].checked=(todo&EXPAND_REPLIES)!=0;boxes[3].checked=(todo&EXPAND_FILTER)!=0;}}static%20showIt(){Global.logger.hide();Global.cfg=new%20CfgWindow();Global.cfg.show();}}class%20LogWindow%20extends%20BaseWindow{constructor(){super();this.id="log-window";this.timeouts=0;this.phantoms=0;this.edit=null;}create(div){this.edit=document.createElement("textarea");this.edit.style.width="100%";this.edit.style.height="100%";this.edit.style.color="#fff";this.edit.style.backgroundColor="#425f9c";div.appendChild(this.edit);}hide(){BaseWindow.prototype.hide.call(this);this.edit=null;}log(s){console.log(s);if(this.edit){this.edit.value=s+"\n"+this.edit.value;}}timeout(){this.timeouts++;}phantom(){this.phantoms++;}counts(){if(this.timeouts>0){this.log(this.timeouts+"%20timeout(s)");}if(this.phantoms>0){this.log(this.phantoms+"%20phantom(s)");}this.log("Responses%20=%20"+Global.root.queryAll(RESPONSE_COUNTER).length);}}class%20Root{constructor(){this.rootNode=document.body;this.usingBody=true;}static%20removeOverlay(){document.querySelectorAll(CSS_LOGIN_STUFF).forEach(item=>{Global.log("Removing%20overlay%20stuff");item.parentNode.removeChild(item);});}query(s){return%20this.rootNode.querySelector(s);}queryAll(s){return%20this.rootNode.querySelectorAll(s);}determine(){const%20EXPANDING="Expanding:%20";const%20div=Dom.findFirstVisible(document.querySelectorAll(POST_ARTICLE));if(!!div){let%20canPost=!!document.querySelector(POST_ACTION);let%20topOnly=!canPost;if(topOnly){if(Dom.roles("grid")<=1){topOnly=Dom.roles("contentinfo")==0;}else%20if(Dom.roles("navigation")==2){topOnly=false;}}else{topOnly=Dom.roles("feed")==2&&Dom.roles("grid")==1&&Dom.roles("contentinfo")==0;}if(topOnly){Global.log(EXPANDING+"Topmost%20post");this.rootNode=div.parentNode;this.usingBody=false;}}if(!this.usingBody){return;}const%20USE_PARENT=true;let%20check=[];check.push([".uiStreamStory","Video%20comments%20on%20right",!USE_PARENT]);check.push(["div.rhcScroller%20.uiScrollableAreaContent","Theater%20mode",USE_PARENT]);check.push([".uiLayer:not(.hidden_elem)","Overlaid%20post",!USE_PARENT]);check.push([".permalinkPost","Permalinked%20post",!USE_PARENT]);check.push(["#contentArea","Classic%20feed",!USE_PARENT]);check.push(["[data-pagelet=\"TahoeRightRail\"]","Full-browser%20video",USE_PARENT]);check.push([FS_ARTICLE,"Full-browser",USE_PARENT]);check.push(["[role=\"main\"]","Main%20content%20area",!USE_PARENT]);check.push(["[role=\"feed\"]","Feed",!USE_PARENT]);check.find(item=>{const%20divs=Dom.filterHidden(document.querySelectorAll(item[0]));let%20div=null;if(divs.length==1){div=divs[0];}if(divs.length==2){div=divs[1];}if(!!div){Global.log(EXPANDING+item[1]);if(item[2]==USE_PARENT){div=div.parentNode;}this.rootNode=div;this.usingBody=false;return%20true;}});}getRoot(){return%20this.rootNode;}getResponseCount(){return%20getResponseCount(this.rootNode);}getContentSize(){let%20result=this.rootNode.scrollHeight;result+=this.getResponseCount();return%20result;}static%20isClassicVideo(){const%20result=!!document.querySelector(".uiStreamStory");return%20result;}static%20prepIfClassicVideo(onDone){let%20wait=0;if(Root.isClassicVideo()){const%20links=document.querySelectorAll(SHOW_COMMENTS);if(links.length>0){Global.log("Making%20sure%20video%20comments%20are%20showing");links[links.length-1].click();wait=100;}}if(onDone){window.setTimeout(onDone,wait);}}isFullBrowserNew(){let%20result=!!Global.root.query(FS_ARTICLE);return%20result;}isNewVideoKind(){let%20result=!!Global.root.query(VIDEO_ARTICLE);return%20result;}isSearchResults(){let%20result=!!Global.root.query("#pagelet_group_search,.p8dawk7l[role=\"presentation\"]");return%20result;}countPosts(){if(Root.isClassicVideo()){return%201;}let%20filter=Array.from(Global.root.queryAll(POST_ROOT));filter=filter.filter(item=>!item.querySelector(POST_ROOT));return%20filter.length;}}class%20Dom{static%20getStyle(node){return%20node.ownerDocument.defaultView.getComputedStyle(node,null);}static%20isHidden(node){while(node&&node.ownerDocument){if(Dom.getStyle(node)["display"]=="none"){return%20true;}if(Dom.getStyle(node)["visibility"]=="hidden"){return%20true;}node=node.parentNode;}return%20false;}static%20filterHidden(nodes){let%20result=[];nodes.forEach(item=>{if(!Dom.isHidden(item)){result.push(item);}});return%20result;}static%20roles(role){return%20Dom.filterHidden(document.querySelectorAll("[role=\""+role+"\"]")).length;}static%20findFirstVisible(nodes){let%20filtered=Dom.filterHidden(nodes);return%20filtered.length>=1?filtered[0]:null;}static%20dumpAncestors(node){while(node){let%20s=node.nodeName;if(node.id){s+="%20id=\""+node.id+"\"";}if(node.className){s+="%20class=\""+node.className+"\"";}if(Dom.isHidden(node)){s+="%20hidden";}Global.log(s);node=node.parentNode;}}static%20upThenDown(node,ancestor,descendant){const%20item=node.parentNode.closest(ancestor);if(item){return%20item.querySelector(descendant);}return%20null;}static%20childIndex(node){return[Array.from(node.parentNode.children).indexOf(node),node.parentNode.childElementCount];}static%20hasTextView(s){const%20words=[/^View%20/,/^%E6%AA%A2%E8%A6%96%E5%8F%A6/,/^%E5%8F%A6%20/,/^%E5%85%B6%E4%BB%96/,/^%E0%A4%86%E0%A4%A3%E0%A4%96%E0%A5%80%20/,/%20%E0%A4%A6%E0%A5%87%E0%A4%96%E0%A5%87%E0%A4%82$/,/%20%E0%A6%9A%E0%A6%BE%E0%A6%93%E0%A6%95$/,/%20%E0%A6%A6%E0%A7%87%E0%A6%96%E0%A7%81%E0%A6%A8$/,/%20%E0%A8%B5%E0%A9%87%E0%A8%96%E0%A9%8B$/,/%20%E0%AA%9C%E0%AB%81%E0%AA%93$/,/%20%E0%AC%A6%E0%AD%87%E0%AC%96%E0%AC%A8%E0%AD%8D%E0%AC%A4%E0%AD%81$/,/%20%E0%AE%95%E0%AE%BE%E0%AE%9F%E0%AF%8D%E0%AE%9F%E0%AF%81$/,/%20%E0%B0%B5%E0%B1%80%E0%B0%95%E0%B1%8D%E0%B0%B7%E0%B0%BF%E0%B0%82%E0%B0%9A%E0%B0%82%E0%B0%A1%E0%B0%BF$/,/%20%E0%B2%B5%E0%B3%80%E0%B2%95%E0%B3%8D%E0%B2%B7%E0%B2%BF%E0%B2%B8%E0%B2%BF$/,/%20%E0%B4%95%E0%B4%BE%E0%B4%A3%E0%B5%81%E0%B4%95$/,/^Ver%20/,/^Afficher%20/,/^%D8%B9%D8%B1%D8%B6%20/,/^%D0%9F%D0%BE%D0%BA%D0%B0%D0%B7%D0%B0%D1%82%D1%8C%20/,/^Lihat%20/,/^Tampilkan%20/,/%E4%BB%B6%E3%82%92%E8%A1%A8%E7%A4%BA$/,/^%D0%9F%D1%80%D0%B5%D0%B3%D0%BB%D0%B5%D0%B4%20/,/%20%EB%B3%B4%EA%B8%B0$/,/^Visualizza%20/,/%20ansehen$/,/^Zobrazit%20/,/^Vis%20/,/^Sj%C3%A5%20/,/^Visa%20/,/^N%C3%A4yt%C3%A4%20/,/^Sko%C3%B0a%20/,/%20weergeven$/,/%20bekijken$/,/^Bekijk%20/];return%20words.some(re=>{return%20s.match(re)!=null;});}static%20hasTextShare(s){const%20words=[/%20Share$/,/%20Shares$/,/%20%E6%AC%A1%E5%88%86%E4%BA%AB$/,/%E6%AC%A1%E5%88%86%E4%BA%AB$/,/%20%E0%A4%B8%E0%A4%BE%E0%A4%AE%E0%A4%BE%E0%A4%AF%E0%A4%BF%E0%A4%95%E0%A5%80%E0%A4%95%E0%A4%B0%E0%A4%A3$/,/%20%E0%A4%B6%E0%A5%87%E0%A4%85%E0%A4%B0$/,/%20%E0%A4%B6%E0%A5%87%E0%A4%AF%E0%A4%B0$/,/%20%E0%A6%B8%E0%A6%B9%E0%A6%AD%E0%A6%BE%E0%A6%97$/,/%20%E0%A6%AD%E0%A6%BE%E0%A6%97-%E0%A6%AC%E0%A6%A4%E0%A7%B0%E0%A6%BE$/,/%20%E0%A6%B6%E0%A7%87%E0%A6%AF%E0%A6%BC%E0%A6%BE%E0%A6%B0$/,/%20%E0%AA%B6%E0%AB%87%E0%AA%B0$/,/%20%E0%AC%B8%E0%AD%87%E0%AD%9F%E0%AC%BE%E0%AC%B0%E0%AD%8D$/,/%20%E0%AC%B8%E0%AD%87%E0%AD%9F%E0%AC%BE%E0%AC%B0$/,/%20%E0%AE%AA%E0%AE%95%E0%AE%BF%E0%AE%B0%E0%AF%8D%E0%AE%B5%E0%AF%81$/,/%20%E0%AE%AA%E0%AE%95%E0%AE%BF%E0%AE%B0%E0%AF%8D%E0%AE%B5%E0%AF%81%E0%AE%95%E0%AE%B3%E0%AF%8D$/,/%20%E0%B0%AD%E0%B0%BE%E0%B0%97%E0%B0%B8%E0%B1%8D%E0%B0%B5%E0%B0%BE%E0%B0%AE%E0%B1%8D%E0%B0%AF%E0%B0%82$/,/%20%E0%B0%AD%E0%B0%BE%E0%B0%97%E0%B0%B8%E0%B1%8D%E0%B0%B5%E0%B0%BE%E0%B0%AE%E0%B1%8D%E0%B0%AF%E0%B0%BE%E0%B0%B2%E0%B1%81$/,/%20%E0%B2%B9%E0%B2%82%E0%B2%9A%E0%B2%BF%E0%B2%95%E0%B3%86$/,/%20%E0%B2%B9%E0%B2%82%E0%B2%9A%E0%B2%BF%E0%B2%95%E0%B3%86%E0%B2%97%E0%B2%B3%E0%B3%81$/,/%20%E0%B4%AA%E0%B4%99%E0%B5%8D%E0%B4%95%E0%B4%BF%E0%B4%9F%E0%B5%BD$/,/%20%E0%B4%AA%E0%B4%99%E0%B5%8D%E0%B4%95%E0%B4%BF%E0%B4%9F%E0%B4%B2%E0%B5%81%E0%B4%95%E0%B5%BE$/,/%20compartido$/,/%20compartida$/,/%20partage$/,/%20partages$/,/^%D9%85%D8%B4%D8%A7%D8%B1%D9%83%D8%A9/,/^%D9%85%D8%B4%D8%A7%D8%B1%D9%83%D8%A7%D8%AA%20/];return%20words.some(re=>{return%20s.match(re)!=null;});}static%20isTextAllComments(s){const%20phrases=["All%20comments".toLowerCase()];return%20phrases.indexOf(s.trim().toLowerCase())>=0;}}function%20getResponseCount(item){return%20item.querySelectorAll(RESPONSE_COUNTER).length;}function%20ensureCommentsShowing(onDone){if(Global.root.isSearchResults()){Global.log("You%20must%20manually%20drill%20down%20into%20a%20search%20result.");if(onDone)onDone();return;}let%20filter=[];const%20n=Global.root.countPosts();if(n>1){Global.log("Examining%20"+n+"%20posts");}Global.root.queryAll(POST_ROOT).forEach(item=>{if(!item.querySelector(POST_ROOT)){const%20link=item.querySelector(SHOW_COMMENTS);if(link&&!item.querySelector(SINGLE_COMMENT_AREA)){filter.push(link);}}});if(filter.length>0){Global.log("Showing%20comment%20area%20for%20"+filter.length+"%20post(s)");clickAndWait(_NONE,onDone,filter,0);}else{if(onDone)onDone();}}function%20ensureCommentsShowingNew(onDone){let%20filter=[];let%20selector=".cwj9ozl2.tvmbv18p";if(Global.root.isFullBrowserNew()){selector="[class=\"cwj9ozl2\"]";}if(Global.root.isNewVideoKind()){selector=".l9j0dhe7.tkr6xdv7.buofh1pr.eg9m0zos";}Global.root.queryAll(POST_ROOT).forEach(item=>{if(!item.querySelector(selector)){const%20link=item.querySelector(".gtad4xkn:first-child%20.auili1gw[role=\"button\"]");if(link&&!Dom.hasTextShare(link.textContent)){filter.push(link);}}});if(filter.length>0){Global.log("Showing%20comment%20area%20for%20"+filter.length+"%20post(s)");clickAndWait(_NONE,onDone,filter,0);}else{if(onDone)onDone();}}function%20isNewWindow(link){return!!link.querySelector("a[target][href]");}function%20newWindowNow(link){const%20anchor=link.querySelector("a[target][href]");Global.log("New%20window:%20"+anchor.textContent);if(!window.open(anchor.getAttribute("href"),anchor.getAttribute("target"))){Global.log("New%20window%20was%20blocked!");}}function%20clickClass(value,onDone){if(Global.escHandler.shouldAbort()){if(onDone)onDone();return;}let%20filter=Array.from(Global.root.queryAll(value)).filter(item=>{if(value===BASE_SEE_MORE){if(item.parentNode.closest(".groupsSideMargin")){return%20false;}if(Dom.isHidden(item)){return%20false;}return%20true;}if(value===SEE_MORE_NEW){if(!!item.childElementCount){return%20false;}if(item.parentNode.nodeName!="SPAN"){return%20true;}if(item.parentNode.parentNode.previousSibling){let%20full=item.parentNode.parentNode.previousSibling.textContent;return%20full.charCodeAt(full.length-1)==8230;}}if(value===EXPOSE_CONTENT){if(isNewWindow(item)){newWindowNow(item);}return%20false;}return%20true;});if(filter.length>0){clickAndWait(value,onDone,filter,0);}else{if(onDone)onDone();}return%20filter.length;}function%20doNotWait(value){return[CSS_SEE_MORE,SEE_MORE_NEW,BASE_SEE_MORE,EXPOSE_CONTENT].indexOf(value)>=0;}function%20getCommentsOrReplies(comments,onDone){if(Global.escHandler.shouldAbort()){if(onDone)onDone();return;}let%20filter=Array.from(Global.root.queryAll(CLASSIC_GET_CONTENT));if(filter.length>0){if(comments){filter=filter.filter(item=>!item.querySelector(CLASSIC_GET_REPLIES));}else{filter=Array.from(Global.root.queryAll(CLASSIC_GET_REPLIES));}}if(filter.length==0){filter=Array.from(Global.root.queryAll(NEW_GET_CONTENT));if(filter.length>0){if(comments){filter=Array.from(Global.root.queryAll(NEW_GET_COMMENTS));}else{filter=filter.filter(item=>!!item.parentNode.parentNode.querySelector(".ozuftl9m"));filter=filter.filter(function(item){if(!!item.closest("ul").parentNode.closest("ul")){return%20true;}item=item.parentNode.parentNode;let%20x=Dom.childIndex(item.parentNode);let%20skip=x[0]==0&&x[1]!=1;if(!skip){skip=x[0]==2&&x[1]==3;}if(skip){skip=!Dom.hasTextView(item.textContent);}return!skip;});filter=filter.filter(item=>!item.querySelector("[role=\"img\"]"));}}}if(filter.length>0){clickAndWait(comments?_COMMENTS:_REPLIES,onDone,filter,0);}else{if(onDone)onDone();}}function%20getBestLabel(link){let%20label=link.getAttribute("aria-label");if(!label&&link.querySelector("._3eol")){label=link.querySelector("._3eol").textContent;}if(!label){label=link.textContent;}label=label.split("\u00a0\u0020\u00b7")[0];label=label.split("\u0020\u00b7")[0];const%20time=link.querySelector("._3eom");if(time&&label.endsWith(time.textContent)){label=label.substring(0,label.length-time.textContent.length);}return%20label;}function%20clickAndWait(value,onDone,links,i){if(Global.escHandler.shouldAbort()){if(onDone)onDone();return;}let%20n=Global.root.getContentSize();Global.log("click%20("+(links.length-i-1)+"%20left):%20"+getBestLabel(links[i]));links[i].click();if(value==_NONE){n=Global.root.getContentSize();}let%20wait=MAX_WAIT;let%20time=WAIT_TIME;if(doNotWait(value)){wait=-1;time=0;}window.setTimeout(()=>waitHelper(value,onDone,links,i,n,wait),time);}function%20waitHelper(value,onDone,links,i,n,wait){if(wait===-1){if(++i<links.length){clickAndWait(value,onDone,links,i);}else{if(onDone)onDone();}return;}if(Global.root.getContentSize()-n!=0){if(++i<links.length){clickAndWait(value,onDone,links,i);}else{if(value==_COMMENTS||value==_REPLIES){getCommentsOrReplies(value==_COMMENTS,onDone);}else{if(onDone)onDone();}}return;}if(window.doPhantomCheck&&!Global.root.getRoot().contains(links[i])){Global.logger.phantom();wait=-1;}if(wait>0){window.setTimeout(()=>waitHelper(value,onDone,links,i,n,--wait),WAIT_TIME);return;}if(wait==0){Global.logger.timeout();}if(++i<links.length){clickAndWait(value,onDone,links,i);}else{if(onDone)onDone();}}function%20pumpOnce(onDone){window.responseCount=Global.root.getResponseCount();window.doPhantomCheck=true;if((todo&EXPAND_COMMENTS)!=0){getCommentsOrReplies(true,()=>pumpOnce2(onDone));}else{pumpOnce2(onDone);}}function%20pumpOnce2(onDone){if((todo&EXPAND_REPLIES)!=0){getCommentsOrReplies(false,()=>pumpOnce3(onDone));}else{pumpOnce3(onDone);}}function%20pumpOnce3(onDone){if(Global.root.getResponseCount()>window.responseCount){window.setTimeout(()=>pumpOnce(onDone),500);}else{delete%20window.doPhantomCheck;if(onDone)onDone();}}function%20setFilter(onDone){window.filters=Array.from(Global.root.queryAll("["+FILTER_ATTR+"]")).filter(item=>item.getAttribute(FILTER_ATTR)!=FILTER_VALUE);window.filters_i=0;window.filters_onDone=onDone;if(window.filters.length>0){Global.log("Changing%20"+window.filters.length+"%20Classic%20filter(s)");}filterOne();}function%20filterOne(){if(window.filters_i<window.filters.length){const%20link=window.filters[window.filters_i++];link.click();window.setTimeout(()=>setFilter2(link),100);}else{if(window.filters_onDone)window.filters_onDone();}}function%20setFilter2(link){const%20menu=document.querySelector("[data-ownerid=\""+link.id+"\"]");if(menu){const%20item=menu.querySelector("["+FILTER_ATTR+"=\""+FILTER_VALUE+"\"]");if(item){const%20post=link.closest(FILTER_ROOT);window.setTimeout(()=>setFilter3(post,50));item.closest("a").click();return;}}link.click();filterOne();}function%20setFilter3(post){if(!post.querySelector(FILTER_DONE)){window.setTimeout(()=>setFilter3(post),200);}else{filterOne();}}function%20setFilterNew(onDone){window.filters=Array.from(Global.root.queryAll(FILTER_NEW));window.filters=window.filters.filter(item=>!item.closest(".sq6gx45u"));window.filters=window.filters.filter(item=>!item.querySelector("h1,svg"));if(window.filters>Global.root.countPosts()){Global.log("Something%20went%20wrong");Global.log("Not%20checking%20"+window.filters.length+"%20New%20filter(s)");if(onDone)onDone;return;}window.filters_i=0;window.filters_onDone=onDone;if(window.filters.length>0){Global.log("Checking%20"+window.filters.length+"%20New%20filter(s)");}filterOneNew();}function%20filterOneNew(){if(window.filters_i<window.filters.length){const%20link=window.filters[window.filters_i++];link.click();window.setTimeout(()=>setFilterNew2(link),100);}else{if(window.filters_onDone)window.filters_onDone();}}function%20setFilterNew2(link){let%20filter=Array.from(document.querySelectorAll(".ama3r5zh[role=\"menu\"],.swg4t2nn[role=\"menu\"]"));if(filter.length==1){const%20menus=filter[0].querySelectorAll("[role=\"menuitem\"]");let%20found=false;for(var%20i=0;i<menus.length;i++){const%20s=menus[i].querySelector("span");if(s&&Dom.isTextAllComments(s.textContent)){found=true;break;}}if(!found){Global.log("\u0027"+"All%20comments"+"\u0027%20not%20found.");i=menus.length-1;}const%20span=menus[i].querySelector("span");let%20text="";if(!!span){text=span.textContent;}if(text.trim()!=link.textContent.trim()){const%20post=link.closest(NEW_ARTICLE);menus[i].click();window.setTimeout(()=>setFilterNew3(post),100);return;}menus[0].closest("[role=\"menu\"]").outerHTML="";}filterOneNew();}function%20setFilterNew3(post){if(!post){Global.log("Something%20went%20wrong.%20Not%20waiting.");}if(!post||!!post.querySelector(FILTER_NEW)){filterOneNew();}else{window.setTimeout(()=>setFilterNew3(post),100);}}class%20Actions{constructor(){this.i=0;this.setUpActions();}setUpActions(){this.actions=[];this.actions.push(onDone=>Root.prepIfClassicVideo(onDone));this.actions.push(onDone=>ensureCommentsShowing(onDone));this.actions.push(onDone=>ensureCommentsShowingNew(onDone));if((todo&EXPAND_FILTER)==0){this.actions.push(onDone=>setFilter(onDone));this.actions.push(onDone=>setFilterNew(onDone));}this.actions.push(onDone=>clickClass(BASE_SEE_MORE,onDone));function%20seeMore(o){o.actions.push(onDone=>clickClass(CSS_SEE_MORE,onDone));o.actions.push(onDone=>clickClass(SEE_MORE_NEW,onDone));}seeMore(this);if((todo&EXPAND_POST)!=0){this.actions.push(onDone=>clickClass(EXPOSE_CONTENT,onDone));}this.actions.push(onDone=>pumpOnce(onDone));seeMore(this);this.actions.push(Session.endSession);this.actions.push(null);}doAction(){if(this.actions[this.i]!==null){this.actions[this.i](()=>window.setTimeout(bind(this,this.doAction),50));this.i++;}}kickOff(){this.i=0;this.doAction();}}class%20Session{static%20init(){if(window.Global){Global=window.Global;Global.escHandler.abort(true);}else{Session.kickOff();}}static%20kickOff(){Global={escHandler:new%20EscHandler(),cfgHandler:new%20CfgHandler(),logger:new%20LogWindow(),root:new%20Root()};Global.log=function(s){Global.logger.log(s);};window.Global=Global;Session.main();}static%20main(){todo=Settings.getInt(SETTINGS_KEY,todo);Global.logger.show();Global.escHandler.on();Global.cfgHandler.on();Root.removeOverlay();Global.root.determine();Global.actions=new%20Actions();Global.actions.kickOff();}static%20endSession(){Global.logger.counts();if(Global.cfgHandler.shouldConfig()){CfgWindow.showIt();return;}Global.ending=true;Global.log("[Press%20\u0027s\u0027%20now%20for%20Settings]");window.setTimeout(Session.maybeEnd,END_DELAY*1000);}static%20maybeEnd(){delete%20Global.ending;if(!Global.cfgHandler.shouldConfig()){Session.trulyEnd();}}static%20trulyEnd(){if(Global.cfg){Global.cfg.hide();delete%20Global.cfg;}Global.escHandler.off();Global.cfgHandler.off();Global.logger.hide();delete%20window.Global;Global=null;}}Session.init();})();
  2.  
  3. javascript:(function(){let%20todo=6;const%20EXPAND_POST=1;const%20EXPAND_COMMENTS=2;const%20EXPAND_REPLIES=4;const%20EXPAND_XLAT=8;const%20EXPAND_FILTER=16;const%20WAIT_TIME=100;const%20MAX_WAIT=20;const%20END_DELAY=3.0;const%20POST_ARTICLE="[class=\"icdlwmnq\"][role=\"article\"]";const%20FS_ARTICLE="[role=\"complementary\"]";const%20ANY_ARTICLE=POST_ARTICLE+","+FS_ARTICLE;const%20VIDEO_FEED="#watch_feed";const%20ROLE_MAIN="[role=\"main\"]";const%20POST_ACTION=".ikduhi8d[role=\"button\"],.ihx95mk1";const%20RESPONSE_COUNTER="[aria-label][role=\"article\"]";const%20GET_CONTENT=".i5oewl5a[role=\"button\"]";const%20GET_COMMENTS=".gt60zsk1%20"+GET_CONTENT;const%20FILTER=".gcj2zyi8%20>%20[role=\"button\"]";const%20FILTER_MENU="[role=\"menu\"]";const%20FILTER_ITEM="[role=\"menuitem\"]";const%20FILTER_ITEM_INNER="span";const%20CSS_LOGIN_STUFF="._5hn6,[data-nosnippet]";const%20SM_COMMENT=".jikcssrz%20:not(span)%20[role=\"button\"],div[dir=\"auto\"]%20:not(span)[role=\"button\"]";const%20SEE_MORE_COMMENT=POST_ARTICLE+"%20"+SM_COMMENT+","+FS_ARTICLE+"%20"+SM_COMMENT;const%20SM_BASE="div.qi72231t.nu7423ey.n3hqoq4p.r86q59rh.b3qcqh3k.fq87ekyn.bdao358l.fsf7x5fv.rse6dlih.s5oniofx.m8h3af8h.l7ghb35v.kjdc1dyq.kmwttqpk.srn514ro.oxkhqvkx.rl78xhln.nch0832m.cr00lzj9.rn8ck1ys.s3jn8y49.icdlwmnq.cxfqmxzd.pbevjfx6.innypi6y";const%20SEE_MORE_BASE=POST_ARTICLE+"%20"+SM_BASE+","+FS_ARTICLE+"%20"+SM_BASE;const%20_NONE="no-value";const%20_COMMENTS="-comments";const%20_REPLIES="-replies";const%20SETTINGS_KEY="expand-all-todo";function%20bind(obj,fn){return%20function(){fn.apply(obj,arguments);};}let%20Global=null;if(!document.querySelectorAll("xx").forEach){Object.prototype.forEach=function(callback){let%20T;if(arguments.length>1){T=arguments[1];}let%20O=Object(this);let%20len=O.length>>>0;let%20k=0;while(k<len){if(k%20in%20O){callback.call(T,O[k],k,O);}k++;}};}class%20EscHandler{constructor(){this.abortNow=false;this.handler=bind(this,this.docKeyDown);}shouldAbort(){return%20this.abortNow;}abort(value){if(value&&!this.shouldAbort()&&!Global.cfg){Global.log("Aborting...");}this.abortNow=value;}on(){this.abortNow=false;document.addEventListener("keydown",this.handler);}off(){this.abortNow=true;document.removeEventListener("keydown",this.handler);}docKeyDown(e){if(e.keyCode==27){e.preventDefault();this.abort(true);if(Global.cfg){Session.trulyEnd();}}}}class%20CfgHandler{constructor(){this.doConfig=false;this.handler=bind(this,this.docKeyDown);}shouldConfig(){return%20this.doConfig;}on(){this.doConfig=false;document.addEventListener("keydown",this.handler);}off(){this.doConfig=true;document.removeEventListener("keydown",this.handler);}docKeyDown(e){if(e.keyCode==="S".charCodeAt(0)){e.preventDefault();if(e.ctrlKey){Settings.removeKey(SETTINGS_KEY);Global.log("Will%20use%20default%20settings");return;}this.doConfig=true;if(Global.ending){CfgWindow.showIt();}}}}class%20Settings{static%20hasValue(value){return%20window.localStorage.getItem(value)!==null;}static%20getValue(value,deflt){if(arguments.length<2){deflt=null;}if(!Settings.hasValue(value)){return%20deflt;}return%20window.localStorage.getItem(value);}static%20getInt(value,deflt){if(arguments.length<2){deflt=-1;}return%20Number.parseInt(Settings.getValue(value,deflt),10);}static%20getBoolean(value,deflt){if(arguments.length<2){deflt="false";}return%20Settings.getValue(value,""+deflt)=="true";}static%20setValue(key,value){return%20window.localStorage.setItem(key,""+value);}static%20removeKey(key){return%20window.localStorage.removeItem(key);}}class%20BaseWindow{constructor(){this.id="base-window";}show(){const%20WANT_W=300;const%20WANT_H=200;const%20sizer=document.querySelector("html");const%20w=sizer.clientWidth;const%20h=sizer.clientHeight;let%20x=0;if(w>WANT_W){x=(w-WANT_W)/2;}let%20y=0;if(h>WANT_H){y=(h-WANT_H)/3;}let%20div=document.createElement("div");div.id=this.id;div.style.direction="ltr";div.style.position="fixed";div.style.zIndex="999999";div.style.left=x+"px";div.style.width=WANT_W+"px";div.style.top=y+"px";div.style.height=WANT_H+"px";div.style.color="#fff";div.style.backgroundColor="#425f9c";document.body.insertAdjacentElement("afterbegin",div);this.create(div);this.init(div);}create(div){}init(div){}hide(){document.querySelectorAll("#"+this.id).forEach(item=>document.body.removeChild(item));}}class%20CfgWindow%20extends%20BaseWindow{constructor(){super();this.id="cfg-window";}create(div){let%20node=document.createElement("p");div.appendChild(node);node.innerHTML="<i>Expand%20All</i>%20Settings";node.style.marginLeft="4px";node.style.fontWeight="bold";const%20boxes=[["Expand%20comments.",EXPAND_COMMENTS],["Expand%20replies.",EXPAND_REPLIES],["Don't%20force%20<i>All%20comments</i>%20filter.",EXPAND_FILTER]];boxes.forEach(item=>{node=document.createElement("p");div.appendChild(node);node.style.marginTop="2px";node.style.marginBottom="2px";let%20node2=document.createElement("input");node.appendChild(node2);node2.type="checkbox";node2.value=item[1];node2.style.marginLeft="15px";node2.style.cursor="pointer";node2=document.createElement("label");node.appendChild(node2);node2.innerHTML=item[0];node2.style.cursor="pointer";node2.style.paddingBottom="5px";node2.style.fontWeight="normal";node2.style.color="#fff";});node=document.createElement("div");div.appendChild(node);node.style.textAlign="center";let%20node2=document.createElement("button");node.appendChild(node2);node2.innerHTML="Done";node2.style.cursor="pointer";node2.addEventListener("click",Session.trulyEnd);div.addEventListener("CheckboxStateChange",CfgWindow.check);div.addEventListener("click",CfgWindow.check);}static%20check(e){let%20node=Dom.upThenDown(e.target,"p","input");if(!!node&&node!=e.target){node.checked=!node.checked;if(node.checked){todo|=Number.parseInt(node.value);}else{todo&=~Number.parseInt(node.value);}Settings.setValue(SETTINGS_KEY,todo);}}init(div){let%20boxes=div.querySelectorAll("input");if(boxes.length===3){boxes[0].checked=(todo&EXPAND_COMMENTS)!=0;boxes[1].checked=(todo&EXPAND_REPLIES)!=0;boxes[2].checked=(todo&EXPAND_FILTER)!=0;}}static%20showIt(){Global.logger.hide();Global.cfg=new%20CfgWindow();Global.cfg.show();}}class%20LogWindow%20extends%20BaseWindow{constructor(){super();this.id="log-window";this.timeouts=0;this.phantoms=0;this.edit=null;}create(div){this.edit=document.createElement("textarea");this.edit.style.width="100%";this.edit.style.height="100%";this.edit.style.color="#fff";this.edit.style.backgroundColor="#425f9c";div.appendChild(this.edit);}hide(){BaseWindow.prototype.hide.call(this);this.edit=null;}log(s){console.log(s);if(this.edit){this.edit.value=s+"\n"+this.edit.value;}}timeout(){this.timeouts++;}phantom(){this.phantoms++;}counts(){if(this.timeouts>0){this.log(this.timeouts+"%20timeout(s)");}if(this.phantoms>0){}this.log("Responses%20showing%20=%20"+Global.root.queryAll(RESPONSE_COUNTER).length);}}class%20Root{constructor(){this.rootNode=document.body;this.usingBody=true;}static%20removeOverlay(){document.querySelectorAll(CSS_LOGIN_STUFF).forEach(item=>{Global.log("Removing%20overlay%20stuff");item.parentNode.removeChild(item);});}query(s){return%20this.rootNode.querySelector(s);}queryAll(s){return%20this.rootNode.querySelectorAll(s);}determine(){if(Dom.filterHidden(document.querySelectorAll(VIDEO_FEED)).length===1){Global.log("Video%20feed;%20please%20drill%20down%20to%20one%20video%20(click%20the%20time%20stamp).");return%20false;}const%20EXPANDING="Expanding:%20";const%20divv=Dom.findFirstVisible(document.querySelectorAll(POST_ARTICLE));if(!!divv){let%20canPost=!!document.querySelector(POST_ACTION);;let%20topOnly=!canPost;if(topOnly){topOnly=Dom.roles("contentinfo")==0;}else{topOnly=Dom.roles("feed")==2&&Dom.roles("grid")==1&&Dom.roles("contentinfo")==0;}if(topOnly){Global.log(EXPANDING+"Topmost%20post");this.rootNode=divv.parentNode;this.usingBody=false;}}if(!this.usingBody){return%20true;}const%20USE_PARENT=true;let%20check=[];check.push([FS_ARTICLE,"Full-browser",USE_PARENT]);check.push([ROLE_MAIN,"Main%20content%20area",!USE_PARENT]);check.find(item=>{const%20divs=Dom.filterHidden(document.querySelectorAll(item[0]));let%20div=null;if(divs.length==1){div=divs[0];}if(divs.length==2){div=divs[1];}if(!!div){Global.log(EXPANDING+item[1]);if(item[2]==USE_PARENT){div=div.parentNode;}this.rootNode=div;this.usingBody=false;return%20true;}});return%20true;}getRoot(){return%20this.rootNode;}getResponseCount(){return%20getResponseCount(this.rootNode);}getContentSize(){let%20result=this.rootNode.scrollHeight;result+=this.getResponseCount();return%20result;}countPosts(){let%20filter=Array.from(Global.root.queryAll(ANY_ARTICLE));return%20filter.length;}}class%20Dom{static%20getStyle(node){return%20node.ownerDocument.defaultView.getComputedStyle(node,null);}static%20isHidden(node){while(node&&node.ownerDocument){if(Dom.getStyle(node)["display"]=="none"){return%20true;}if(Dom.getStyle(node)["visibility"]=="hidden"){return%20true;}node=node.parentNode;}return%20false;}static%20filterHidden(nodes){let%20result=[];if(nodes){nodes.forEach(item=>{if(!Dom.isHidden(item)){result.push(item);}});}return%20result;}static%20roles(role){return%20Dom.filterHidden(document.querySelectorAll("[role=\""+role+"\"]")).length;}static%20findFirstVisible(nodes){if(!nodes){return%20null;}let%20filtered=Dom.filterHidden(nodes);return%20filtered.length>=1?filtered[0]:null;}static%20dumpAncestors(node){while(node){let%20s=node.nodeName;if(node.id){s+="%20id=\""+node.id+"\"";}if(node.className){s+="%20class=\""+node.className+"\"";}if(Dom.isHidden(node)){s+="%20hidden";}if(node.role){s+="%20role=\""+node.role+"\"";}Global.log(s);node=node.parentNode;}}static%20upThenDown(node,ancestor,descendant){const%20item=node.parentNode.closest(ancestor);if(item){return%20item.querySelector(descendant);}return%20null;}static%20childIndex(node){return[Array.from(node.parentNode.children).indexOf(node),node.parentNode.childElementCount];}static%20hasTextView(s){const%20words=[/^View%20/,/^%E6%AA%A2%E8%A6%96%E5%8F%A6/,/^%E5%8F%A6%20/,/^%E5%85%B6%E4%BB%96/,/^%E0%A4%86%E0%A4%A3%E0%A4%96%E0%A5%80%20/,/%20%E0%A4%A6%E0%A5%87%E0%A4%96%E0%A5%87%E0%A4%82$/,/%20%E0%A6%9A%E0%A6%BE%E0%A6%93%E0%A6%95$/,/%20%E0%A6%A6%E0%A7%87%E0%A6%96%E0%A7%81%E0%A6%A8$/,/%20%E0%A8%B5%E0%A9%87%E0%A8%96%E0%A9%8B$/,/%20%E0%AA%9C%E0%AB%81%E0%AA%93$/,/%20%E0%AC%A6%E0%AD%87%E0%AC%96%E0%AC%A8%E0%AD%8D%E0%AC%A4%E0%AD%81$/,/%20%E0%AE%95%E0%AE%BE%E0%AE%9F%E0%AF%8D%E0%AE%9F%E0%AF%81$/,/%20%E0%B0%B5%E0%B1%80%E0%B0%95%E0%B1%8D%E0%B0%B7%E0%B0%BF%E0%B0%82%E0%B0%9A%E0%B0%82%E0%B0%A1%E0%B0%BF$/,/%20%E0%B2%B5%E0%B3%80%E0%B2%95%E0%B3%8D%E0%B2%B7%E0%B2%BF%E0%B2%B8%E0%B2%BF$/,/%20%E0%B4%95%E0%B4%BE%E0%B4%A3%E0%B5%81%E0%B4%95$/,/^Ver%20/,/^Afficher%20/,/^%D8%B9%D8%B1%D8%B6%20/,/^%D0%9F%D0%BE%D0%BA%D0%B0%D0%B7%D0%B0%D1%82%D1%8C%20/,/^Lihat%20/,/^Tampilkan%20/,/%E4%BB%B6%E3%82%92%E8%A1%A8%E7%A4%BA$/,/^%D0%9F%D1%80%D0%B5%D0%B3%D0%BB%D0%B5%D0%B4%20/,/%20%EB%B3%B4%EA%B8%B0$/,/^Visualizza%20/,/%20ansehen$/,/^Zobrazit%20/,/^Vis%20/,/^Sj%C3%A5%20/,/^Visa%20/,/^N%C3%A4yt%C3%A4%20/,/^Sko%C3%B0a%20/,/%20weergeven$/,/%20bekijken$/,/^Bekijk%20/];return%20words.some(re=>{return%20s.match(re)!=null;});}static%20isTextAllComments(s){const%20phrases=["All%20comments".toLowerCase()];return%20phrases.indexOf(s.trim().toLowerCase())>=0;}}function%20getResponseCount(item){return%20item.querySelectorAll(RESPONSE_COUNTER).length;}function%20ensureCommentsShowing(onDone){let%20n=Global.root.countPosts();if(n>1){Global.log("Found%20"+n+"%20posts");}let%20filter=[];if(filter.length>0){Global.log("Showing%20comment%20area%20for%20"+filter.length+"%20post(s)");clickAndWait(_NONE,onDone,filter,0);}else{if(onDone)onDone();}}function%20clickClass(value,onDone){if(Global.escHandler.shouldAbort()){if(onDone)onDone();return;}let%20filter=Array.from(Global.root.queryAll(value)).filter(item=>{if(value===SEE_MORE_BASE){if(item.closest(RESPONSE_COUNTER)){return%20false;}}if(value===SEE_MORE_COMMENT){if(!item.closest(RESPONSE_COUNTER)){return%20false;}}if(value===SEE_MORE_COMMENT||value===SEE_MORE_BASE){if(!!item.childElementCount){return%20false;}}if(value===SEE_MORE_BASE){if(item.parentNode.parentNode.previousSibling){let%20full=item.parentNode.parentNode.previousSibling.textContent;return%20full.charCodeAt(full.length-1)==8230;}}return%20true;});if(filter.length>0){clickAndWait(value,onDone,filter,0);}else{if(onDone)onDone();}return%20filter.length;}function%20doNotWait(value){return[SEE_MORE_COMMENT,SEE_MORE_BASE].indexOf(value)>=0;}function%20getCommentsOrReplies(comments,onDone){if(Global.escHandler.shouldAbort()){if(onDone)onDone();return;}let%20filter=Array.from(Global.root.queryAll(GET_CONTENT));if(filter.length>0){if(comments){filter=Array.from(Global.root.queryAll(GET_COMMENTS));filter=filter.filter(item=>!item.parentNode.closest("li"));}else{filter=filter.filter(function(item){if(!!item.closest("ul")&&!!item.closest("ul").parentNode.closest("ul")){return%20true;}let%20x=Dom.childIndex(item.parentNode);let%20skip=x[0]==0&&x[1]!=1;if(!skip){skip=x[0]==2&&x[1]==3;}if(skip){skip=!Dom.hasTextView(item.textContent);}return!skip;});}}if(filter.length>0){clickAndWait(comments?_COMMENTS:_REPLIES,onDone,filter,0);}else{if(onDone)onDone();}}function%20getBestLabel(link){let%20label=link.getAttribute("aria-label");if(!label){label=link.textContent;}label=label.split("\u00a0\u0020\u00b7")[0];label=label.split("\u0020\u00b7")[0];return%20label;}function%20clickAndWait(value,onDone,links,i){if(Global.escHandler.shouldAbort()){if(onDone)onDone();return;}let%20n=Global.root.getContentSize();Global.log("click%20("+(links.length-i-1)+"%20left):%20"+getBestLabel(links[i]));links[i].click();if(value==_NONE){n=Global.root.getContentSize();}let%20wait=MAX_WAIT;let%20time=WAIT_TIME;if(doNotWait(value)){wait=-1;time=0;}window.setTimeout(()=>waitHelper(value,onDone,links,i,n,wait),time);}function%20waitHelper(value,onDone,links,i,n,wait){if(wait===-1){if(++i<links.length){clickAndWait(value,onDone,links,i);}else{if(onDone)onDone();}return;}if(Global.root.getContentSize()-n!=0){if(++i<links.length){clickAndWait(value,onDone,links,i);}else{if(value==_COMMENTS||value==_REPLIES){getCommentsOrReplies(value==_COMMENTS,onDone);}else{if(onDone)onDone();}}return;}if(window.doPhantomCheck&&!Global.root.getRoot().contains(links[i])){Global.logger.phantom();wait=-1;}if(wait>0){window.setTimeout(()=>waitHelper(value,onDone,links,i,n,--wait),WAIT_TIME);return;}if(wait==0){Global.logger.timeout();}if(++i<links.length){clickAndWait(value,onDone,links,i);}else{if(onDone)onDone();}}function%20pumpOnce(onDone){window.responseCount=Global.root.getResponseCount();window.doPhantomCheck=true;if((todo&EXPAND_COMMENTS)!=0){getCommentsOrReplies(true,()=>pumpOnce2(onDone));}else{pumpOnce2(onDone);}}function%20pumpOnce2(onDone){if((todo&EXPAND_REPLIES)!=0){getCommentsOrReplies(false,()=>pumpOnce3(onDone));}else{pumpOnce3(onDone);}}function%20pumpOnce3(onDone){if(Global.root.getResponseCount()>window.responseCount){window.setTimeout(()=>pumpOnce(onDone),500);}else{delete%20window.doPhantomCheck;if(onDone)onDone();}}function%20setFilter(onDone){window.filters=Array.from(Global.root.queryAll(FILTER));if(window.filters>Global.root.countPosts()){Global.log("Something%20went%20wrong");Global.log("Not%20checking%20"+window.filters.length+"%20filter(s)");if(onDone)onDone;return;}window.filters_i=0;window.filters_onDone=onDone;if(window.filters.length>0){Global.log("Checking%20"+window.filters.length+"%20filter(s)");}filterOne();}function%20filterOne(){if(window.filters_i<window.filters.length){const%20link=window.filters[window.filters_i++];link.click();window.setTimeout(()=>setFilter2(link),100);}else{if(window.filters_onDone)window.filters_onDone();}}function%20setFilter2(link){let%20filter=Array.from(document.querySelectorAll(FILTER_MENU));if(filter.length==1){const%20menus=filter[0].querySelectorAll(FILTER_ITEM);let%20found=false;for(var%20i=0;i<menus.length;i++){const%20s=menus[i].querySelector(FILTER_ITEM_INNER);if(s&&Dom.isTextAllComments(s.textContent)){found=true;break;}}if(!found){Global.log("\u0027"+"All%20comments"+"\u0027%20not%20found.");i=menus.length-1;}const%20span=menus[i].querySelector(FILTER_ITEM_INNER);let%20text="";if(!!span){text=span.textContent;}if(text.trim()!=link.textContent.trim()){Global.log(window.filters_i+":%20changing%20\""+link.textContent.trim()+"\"");const%20post=link.closest(ANY_ARTICLE);menus[i].click();window.setTimeout(()=>setFilter3(post),100);return;}menus[0].closest(FILTER_MENU).outerHTML="";}else%20if(filter.length>1){Global.log("Comment%20filter%20failure!");}filterOne();}function%20setFilter3(post){if(!post){Global.log("Something%20went%20wrong.%20Not%20waiting.");}if(!post||!!post.querySelector(FILTER)){filterOne();}else{window.setTimeout(()=>setFilter3(post),100);}}class%20Actions{constructor(){this.i=0;this.setUpActions();}setUpActions(){this.actions=[];this.actions.push(onDone=>ensureCommentsShowing(onDone));if((todo&EXPAND_FILTER)==0){this.actions.push(onDone=>setFilter(onDone));}function%20seeMore(o){o.actions.push(onDone=>clickClass(SEE_MORE_COMMENT,onDone));}this.actions.push(onDone=>clickClass(SEE_MORE_BASE,onDone));seeMore(this);this.actions.push(onDone=>pumpOnce(onDone));seeMore(this);this.actions.push(Session.endSession);this.actions.push(null);}doAction(){if(this.actions[this.i]!==null){this.actions[this.i](()=>window.setTimeout(bind(this,this.doAction),50));this.i++;}}kickOff(){this.i=0;this.doAction();}}class%20Session{static%20init(){if(window.Global){Global=window.Global;Global.escHandler.abort(true);}else{Session.kickOff();}}static%20kickOff(){Global={escHandler:new%20EscHandler(),cfgHandler:new%20CfgHandler(),logger:new%20LogWindow(),root:new%20Root()};Global.log=function(s){Global.logger.log(s);};window.Global=Global;Session.main();}static%20main(){todo=Settings.getInt(SETTINGS_KEY,todo);Global.logger.show();Global.escHandler.on();Global.cfgHandler.on();Root.removeOverlay();if(Global.root.determine()){Global.actions=new%20Actions();Global.actions.kickOff();}else{Session.endSession();}}static%20endSession(){Global.logger.counts();if(Global.cfgHandler.shouldConfig()){CfgWindow.showIt();return;}Global.ending=true;Global.log("[Press%20\u0027s\u0027%20now%20for%20Settings]");window.setTimeout(Session.maybeEnd,END_DELAY*1000);}static%20maybeEnd(){delete%20Global.ending;if(!Global.cfgHandler.shouldConfig()){Session.trulyEnd();}}static%20trulyEnd(){if(Global.cfg){Global.cfg.hide();delete%20Global.cfg;}Global.escHandler.off();Global.cfgHandler.off();Global.logger.hide();delete%20window.Global;Global=null;}}Session.init();})();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement