javascript - How can I improve this script to delete a left over table? -



javascript - How can I improve this script to delete a left over table? -

this script makes deletes content specific users forum. working intended there still left on element (table) deleted content. ideas highly appreciated.

code: https://greasyfork.org/scripts/2690-fitmisc-total-ignore/code

// ==userscript== // @name fitmisc_total_ignore // @author arris // @description script designed completly eradicate sight worst posters on fitmisc.com // @include http://fitmisc.com/* // @namespace http://fitmisc.com/ // @version 0.9 // ==/userscript== function canignore(suser) { if( suser.match(/niko/i) ) homecoming true; if( suser.match(/thesavagepony/i) ) homecoming true; if( suser.match(/lloyd banks/i) ) homecoming true; if( suser.match(/lil b/i) ) homecoming true; if( suser.match(/round-mound/i) ) homecoming true; homecoming false; } function setignorethread() { var a; var s; a=document.evaluate( "//div[starts-with(@class, 'threadmeta')]", document, null, xpathresult.unordered_node_snapshot_type, null); (var i=0; i<a.snapshotlength; i++) { s=a.snapshotitem(i).innerhtml; if( canignore(s) ) { //a.snapshotitem(i).parentnode.parentnode.parentnode.style.display = 'none'; a.snapshotitem(i).parentnode.parentnode.parentnode.innerhtml = ''; } } } function setignorepost() { var a; var s; a=document.evaluate( "//div[starts-with(@class, 'username_container')]", document, null, xpathresult.unordered_node_snapshot_type, null); (var i=0; i<a.snapshotlength; i++) { s=a.snapshotitem(i).innerhtml; if( canignore(s) ) { //a.snapshotitem(i).parentnode.parentnode.parentnode.parentnode.parentnode.parentnode.style.display = 'none'; a.snapshotitem(i).parentnode.parentnode.parentnode.innerhtml = '<li class="postbitlegacy postbitim postcontainer old" style="background:white;border-color:white;"></li>'; } } } function setignorequote() { var a; var s; a=document.evaluate( "//div[starts-with(@class, 'bbcode_postedby')]", document, null, xpathresult.unordered_node_snapshot_type, null); (var i=0; i<a.snapshotlength; i++) { s=a.snapshotitem(i).innerhtml; if( canignore(s) ) { //a.snapshotitem(i).parentnode.parentnode.parentnode.style.display = 'none'; a.snapshotitem(i).parentnode.innerhtml = ''; } } } if(window.opera) { //opera (function(){ document.addeventlistener('domcontentloaded', function() { setignorethread(); setignorepost(); setignorequote(); }, false); })() } else { setignorethread(); setignorepost(); setignorequote(); }

instead of hardcode usernames each in dedicated regulare look consider generation of single look matching item of array of ignored user names. utilize regexp.test() method when don't need store result.

(i've removed user names in examples, except anonymous operator business relationship "op". don't defamation in public.)

var ignoredusers = ['user 1', 'another user', 'op', 'yet user'] ; function canignore(suser) { homecoming new regexp(ignoredusers.join('|'), 'i').test(suser); }

however, there's no need extract user names, check them against regular expressions , farther processing, since using xpath expressions can find content , step in dom tree. capable retrieve text nodes 1 of list of users within container class , give ancestors ([grand]parents) selected class.

// = =userscript= = // @name fitmisc_total_ignore // @author arris // @description script designed completly eradicate sight worst posters on fitmisc.com // @include http://fitmisc.com/* // @namespace http://fitmisc.com/ // @grant gm_xpath // @version 0.9 // = =/userscript= = var // todo: gm_ get/set value json ; set users igno list mouse click ignoredusers = ['user 1', 'another user', 'op', 'yet user'] ; function removecontents(ignorelist) { if(ignorelist instanceof array && ignorelist.length) gm_xpath ( { path: "//div[@class='username_container']//*[text() = '" + ignorelist.map(function(user) { homecoming user.replace("'", "\\'"); } ).join("' or text() = '") + "']/ancestor::li[contains(@class, 'postcontainer')]", :true } ).foreach(function(elem){ elem.parentelement.removechild(elem); }); } removecontents(ignoredusers);

since users accounts renamed, consider filter user id, e.g. in href attribute of profile link or photo, instead of relying on changable names.

the expample above job on thread posts. can combine multiple xpath expressions 1 "|" char.

javascript greasemonkey

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -