Advertisement
nomcarver

Block Requesters

May 8th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.75 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Block Requesters (Fixed)
  3. // @author Aphit (adopted from Ergo)
  4. // @version 1.0.0
  5. // @description Hide HITs from requesters you're not interested in (FIXED FOR GOOGLE CHROME)
  6. // @include https://www.mturk.com/mturk/findhits*
  7. // @include https://www.mturk.com/mturk/searchbar*
  8. // @include https://www.mturk.com/mturk/viewsearchbar*
  9. // @include https://www.mturk.com/mturk/sorthits*
  10. // @include https://www.mturk.com/mturk/viewhits*
  11. // @include https://www.mturk.com/mturk/accept*
  12. // @include https://www.mturk.com/mturk/preview*
  13. // @include https://www.mturk.com/mturk/return*
  14. // @include https://www.mturk.com/mturk/sortsearchbar*
  15. // ==/UserScript==
  16.  
  17.  
  18.  
  19. //CHANGES
  20.  
  21. function GM_setValue( cookieName, cookieValue, lifeTime ) {
  22. if( !cookieName ) { return; }
  23. if( lifeTime == "delete" ) { lifeTime = -10; } else { lifeTime = 31536000; }
  24. document.cookie = escape( cookieName ) + "=" + escape( getRecoverableString( cookieValue ) ) +
  25. ";expires=" + ( new Date( ( new Date() ).getTime() + ( 1000 * lifeTime ) ) ).toGMTString() + ";path=/";
  26. }
  27.  
  28. function GM_getValue( cookieName, oDefault ) {
  29. var cookieJar = document.cookie.split( "; " );
  30. for( var x = 0; x < cookieJar.length; x++ ) {
  31. var oneCookie = cookieJar[x].split( "=" );
  32. if( oneCookie[0] == escape( cookieName ) ) {
  33. try {
  34. eval('var footm = '+unescape( oneCookie[1] ));
  35. } catch(e) { return oDefault; }
  36. return footm;
  37. }
  38. }
  39. return oDefault;
  40. }
  41.  
  42. function GM_deleteValue( oKey ) {
  43. //yes, they didn't seem to provide a way to delete variables in Greasemonkey, and the user must use about:config to
  44. //delete them - so the stored variables will pile up forever ...
  45. GM_setValue( oKey, '', 'delete' );
  46. }
  47.  
  48. var GM_falsifiedMenuCom = [], hasPageGMloaded = false;
  49. window.addEventListener('load',function () {hasPageGMloaded=true;doGMMeenoo();},false)
  50. function GM_registerMenuCommand( oText, oFunc ) {
  51. GM_falsifiedMenuCom[GM_falsifiedMenuCom.length] = [oText,oFunc];
  52. if( hasPageGMloaded ) { doGMMeenoo(); } //if the page has already loaded, do it now
  53. }
  54.  
  55. function doGMMeenoo() {
  56. if( !GM_falsifiedMenuCom.length ) { return; }
  57. //create a menu of commands in the top corner
  58. var foo = document.getElementById('GM_Falsify_me'), bar, par = document.body ? document.body : document.documentElement;
  59. if( foo ) { par.removeChild(foo); }
  60. foo = document.createElement('GMmenoo');
  61. foo.id = 'GM_Falsify_me';
  62. par.appendChild(foo);
  63. with( foo.style ) {
  64. border = '1px solid #000';
  65. backgroundColor = '#bbf';
  66. color = '#000';
  67. position = 'fixed';
  68. zIndex = '100000';
  69. top = '0px';
  70. right = '0px';
  71. padding = '2px';
  72. overflow = 'hidden';
  73. height = '1.3em';
  74. }
  75. foo.appendChild(bar = document.createElement('b'))
  76. bar.style.cursor = 'move';
  77. bar.onclick = function () {
  78. this.parentNode.style.left = this.parentNode.style.left ? '' : '0px';
  79. this.parentNode.style.right = this.parentNode.style.right ? '' : '0px';
  80. };
  81. bar.appendChild(document.createTextNode('User Script Commands'));
  82. foo.appendChild(bar = document.createElement('ul'));
  83. bar.style.margin = '0px';
  84. bar.style.padding = '0px';
  85. bar.style.listStylePosition = 'inside';
  86. for( var i = 0; GM_falsifiedMenuCom[i]; i++ ) {
  87. var baz = document.createElement('li'), bing;
  88. baz.appendChild(bing = document.createElement('a'));
  89. bing.setAttribute('href','#');
  90. bing.onclick = new Function('GM_falsifiedMenuCom['+i+'][1](arguments[0]);return false;');
  91. bing.onfocus = function () { this.parentNode.style.height = ''; };
  92. bing.onblur = function () { this.parentNode.style.height = '1.3em'; };
  93. bing.appendChild(document.createTextNode(GM_falsifiedMenuCom[i][0]));
  94. bar.appendChild(baz);
  95. }
  96. foo.onmouseover = function () { this.style.height = ''; };
  97. foo.onmouseout = function () { this.style.height = '1.3em'; };
  98. }
  99.  
  100. // GM_log = opera.postError;
  101.  
  102. window._content = window;
  103.  
  104. function getRecoverableString(oVar,notFirst) {
  105. var oType = typeof(oVar);
  106. if( ( oType == 'null' ) || ( oType == 'object' && !oVar ) ) {
  107. //most browsers say that the typeof for null is 'object', but unlike a real
  108. //object, it will not have any overall value
  109. return 'null';
  110. }
  111. if( oType == 'undefined' ) { return 'window.uDfXZ0_d'; }
  112. if( oType == 'object' ) {
  113. //Safari throws errors when comparing non-objects with window/document/etc
  114. if( oVar == window ) { return 'window'; }
  115. if( oVar == document ) { return 'document'; }
  116. if( oVar == document.body ) { return 'document.body'; }
  117. if( oVar == document.documentElement ) { return 'document.documentElement'; }
  118. }
  119. if( oVar.nodeType && ( oVar.childNodes || oVar.ownerElement ) ) { return '{error:\'DOM node\'}'; }
  120. if( !notFirst ) {
  121. Object.prototype.toRecoverableString = function (oBn) {
  122. if( this.tempLockIgnoreMe ) { return '{\'LoopBack\'}'; }
  123. this.tempLockIgnoreMe = true;
  124. var retVal = '{', sepChar = '', j;
  125. for( var i in this ) {
  126. if( i == 'toRecoverableString' || i == 'tempLockIgnoreMe' || i == 'prototype' || i == 'constructor' ) { continue; }
  127. if( oBn && ( i == 'index' || i == 'input' || i == 'length' || i == 'toRecoverableObString' ) ) { continue; }
  128. j = this[i];
  129. if( !i.match(basicObPropNameValStr) ) {
  130. //for some reason, you cannot use unescape when defining peoperty names inline
  131. for( var x = 0; x < cleanStrFromAr.length; x++ ) {
  132. i = i.replace(cleanStrFromAr[x],cleanStrToAr[x]);
  133. }
  134. i = '\''+i+'\'';
  135. } else if( window.ActiveXObject && navigator.userAgent.indexOf('Mac') + 1 && !navigator.__ice_version && window.ScriptEngine && ScriptEngine() == 'JScript' && i.match(/^\d+$/) ) {
  136. //IE mac does not allow numerical property names to be used unless they are quoted
  137. i = '\''+i+'\'';
  138. }
  139. retVal += sepChar+i+':'+getRecoverableString(j,true);
  140. sepChar = ',';
  141. }
  142. retVal += '}';
  143. this.tempLockIgnoreMe = false;
  144. return retVal;
  145. };
  146. Array.prototype.toRecoverableObString = Object.prototype.toRecoverableString;
  147. Array.prototype.toRecoverableString = function () {
  148. if( this.tempLock ) { return '[\'LoopBack\']'; }
  149. if( !this.length ) {
  150. var oCountProp = 0;
  151. for( var i in this ) { if( i != 'toRecoverableString' && i != 'toRecoverableObString' && i != 'tempLockIgnoreMe' && i != 'prototype' && i != 'constructor' && i != 'index' && i != 'input' && i != 'length' ) { oCountProp++; } }
  152. if( oCountProp ) { return this.toRecoverableObString(true); }
  153. }
  154. this.tempLock = true;
  155. var retVal = '[';
  156. for( var i = 0; i < this.length; i++ ) {
  157. retVal += (i?',':'')+getRecoverableString(this[i],true);
  158. }
  159. retVal += ']';
  160. delete this.tempLock;
  161. return retVal;
  162. };
  163. Boolean.prototype.toRecoverableString = function () {
  164. return ''+this+'';
  165. };
  166. Date.prototype.toRecoverableString = function () {
  167. return 'new Date('+this.getTime()+')';
  168. };
  169. Function.prototype.toRecoverableString = function () {
  170. return this.toString().replace(/^\s+|\s+$/g,'').replace(/^function\s*\w*\([^\)]*\)\s*\{\s*\[native\s+code\]\s*\}$/i,'function () {[\'native code\'];}');
  171. };
  172. Number.prototype.toRecoverableString = function () {
  173. if( isNaN(this) ) { return 'Number.NaN'; }
  174. if( this == Number.POSITIVE_INFINITY ) { return 'Number.POSITIVE_INFINITY'; }
  175. if( this == Number.NEGATIVE_INFINITY ) { return 'Number.NEGATIVE_INFINITY'; }
  176. return ''+this+'';
  177. };
  178. RegExp.prototype.toRecoverableString = function () {
  179. return '\/'+this.source+'\/'+(this.global?'g':'')+(this.ignoreCase?'i':'');
  180. };
  181. String.prototype.toRecoverableString = function () {
  182. var oTmp = escape(this);
  183. if( oTmp == this ) { return '\''+this+'\''; }
  184. return 'unescape(\''+oTmp+'\')';
  185. };
  186. }
  187. if( !oVar.toRecoverableString ) { return '{error:\'internal object\'}'; }
  188. var oTmp = oVar.toRecoverableString();
  189. if( !notFirst ) {
  190. //prevent it from changing for...in loops that the page may be using
  191. delete Object.prototype.toRecoverableString;
  192. delete Array.prototype.toRecoverableObString;
  193. delete Array.prototype.toRecoverableString;
  194. delete Boolean.prototype.toRecoverableString;
  195. delete Date.prototype.toRecoverableString;
  196. delete Function.prototype.toRecoverableString;
  197. delete Number.prototype.toRecoverableString;
  198. delete RegExp.prototype.toRecoverableString;
  199. delete String.prototype.toRecoverableString;
  200. }
  201. return oTmp;
  202. }
  203. var basicObPropNameValStr = /^\w+$/, cleanStrFromAr = new Array(/\\/g,/'/g,/"/g,/\r/g,/\n/g,/\f/g,/\t/g,new RegExp('-'+'->','g'),new RegExp('<!-'+'-','g'),/\//g), cleanStrToAr = new Array('\\\\','\\\'','\\\"','\\r','\\n','\\f','\\t','-\'+\'->','<!-\'+\'-','\\\/');
  204.  
  205. /* GM_xmlhttpRequest implementation adapted from the
  206. Turnabout GM compatibility library:
  207. http://www.reifysoft.com/turnabout.php
  208. Used under the following license:
  209.  
  210. Copyright (c) 2005, Reify Software, Inc.
  211. All rights reserved.
  212.  
  213. Redistribution and use in source and binary forms,
  214. with or without modification, are permitted provided
  215. that the following conditions are met:
  216.  
  217. 1) Redistributions of source code must retain the
  218. above copyright notice, this list of conditions
  219. and the following disclaimer.
  220. 2) Redistributions in binary form must reproduce the
  221. above copyright notice, this list of conditions
  222. and the following disclaimer in the documentation
  223. and/or other materials provided with the
  224. distribution.
  225. 3) Neither the name of the Reify Software, Inc. nor
  226. the names of its contributors may be used to
  227. endorse or promote products derived from this
  228. software without specific prior written permission.
  229.  
  230. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
  231. AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  232. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  233. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  234. PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  235. THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
  236. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  237. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  238. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  239. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  240. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  241. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  242. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  243. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  244. OF SUCH DAMAGE.
  245.  
  246. */
  247.  
  248. //yes, I know the domain limitations, but it's better than an outright error
  249. function GM_xmlhttpRequest(details) {
  250. var xmlhttp = new XMLHttpRequest();
  251. xmlhttp.onreadystatechange = function() {
  252. var responseState = {
  253. responseXML:(xmlhttp.readyState==4 ? xmlhttp.responseXML : ''),
  254. responseText:(xmlhttp.readyState==4 ? xmlhttp.responseText : ''),
  255. readyState:xmlhttp.readyState,
  256. responseHeaders:(xmlhttp.readyState==4 ? xmlhttp.getAllResponseHeaders() : ''),
  257. status:(xmlhttp.readyState==4 ? xmlhttp.status : 0),
  258. statusText:(xmlhttp.readyState==4 ? xmlhttp.statusText : '')
  259. }
  260. if (details["onreadystatechange"]) {
  261. details["onreadystatechange"](responseState);
  262. }
  263. if (xmlhttp.readyState==4) {
  264. if (details["onload"] && xmlhttp.status>=200 && xmlhttp.status<300) {
  265. details["onload"](responseState);
  266. }
  267. if (details["onerror"] && (xmlhttp.status<200 || xmlhttp.status>=300)) {
  268. details["onerror"](responseState);
  269. }
  270. }
  271. }
  272. try {
  273. //cannot do cross domain
  274. xmlhttp.open(details.method, details.url);
  275. } catch(e) {
  276. if( details["onerror"] ) {
  277. //simulate a real error
  278. details["onerror"]({responseXML:'',responseText:'',readyState:4,responseHeaders:'',status:403,statusText:'Forbidden'});
  279. }
  280. return;
  281. }
  282. if (details.headers) {
  283. for (var prop in details.headers) {
  284. xmlhttp.setRequestHeader(prop, details.headers[prop]);
  285. }
  286. }
  287. xmlhttp.send((typeof(details.data)!='undefined')?details.data:null);
  288. }
  289.  
  290. function GM_addStyle(css) {
  291. var NSURI = 'http://www.w3.org/1999/xhtml';
  292. var hashead = document.getElementsByTagName('head')[0];
  293. var parentel = hashead || document.documentElement;
  294. var newElement = document.createElementNS(NSURI,'link');
  295. newElement.setAttributeNS(NSURI,'rel','stylesheet');
  296. newElement.setAttributeNS(NSURI,'type','text/css');
  297. newElement.setAttributeNS(NSURI,'href','data:text/css,'+encodeURIComponent(css));
  298. if( hashead ) {
  299. parentel.appendChild(newElement);
  300. } else {
  301. parentel.insertBefore(newElement,parentel.firstChild);
  302. }
  303. }
  304.  
  305. if(window.navigator.vendor.match(/Google/)) {
  306. var div = document.createElement("div");
  307. div.setAttribute("onclick", "return window;");
  308. unsafeWindow = div.onclick();
  309. };
  310.  
  311.  
  312. //CHANGES
  313.  
  314.  
  315.  
  316. requesterIndex = GM_getValue("requesterIndex");
  317. if(!requesterIndex) {
  318. //alert(requesterIndex);
  319. requesterIndex="";
  320.  
  321. GM_setValue("requesterIndex","");
  322. }
  323.  
  324.  
  325. function showUpdates() {
  326. updated = GM_getValue('requesterUpdated');
  327. if (updated) {
  328. tables = document.evaluate("//table",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
  329. table = tables.snapshotItem(6);
  330. action = updated.split(',');
  331. rId = action[1].split('::')[0];
  332. rName = action[1].split('::')[1];
  333. div = document.createElement('div');
  334. div.id = 'updated';
  335. status = "<div class='message success'><h6><span id='alertboxHeader'>"+action[0]+" "+rName;
  336. if (action[0]=='Blocked') {
  337. status+=" <a style='font-size:80%;' href='javascript:unblockRequester(\""+rId+"\",\""+rName+"\");' title='Unblock this requester'>undo</a>";
  338. }
  339. div.innerHTML = status + "</h6></span></div>";
  340. table.parentNode.insertBefore(div, table);
  341. GM_deleteValue('requesterUpdated');
  342. }
  343. }
  344.  
  345. function hideHIT(element) {
  346. pa=element, step=0;
  347. while (step++ < 14) {
  348. ch = pa;
  349. pa = pa.parentNode;
  350. }
  351. pa.className = "blocked";
  352. }
  353.  
  354. function unhideHIT(element) {
  355. pa=element, step=0;
  356. while (step++ < 14) {
  357. ch = pa;
  358. pa = pa.parentNode;
  359. }
  360. pa.className = "";
  361. }
  362.  
  363. function hideMatchingHITs() {
  364. var numBlocked=0;
  365. theseRequesters = document.evaluate("//a[starts-with(@href,'/mturk/searchbar?selectedSearchType=hitgroups&requesterId=')]",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
  366. for (i=0; i<theseRequesters.snapshotLength; i++) {
  367. rLink = theseRequesters.snapshotItem(i);
  368. rLink.parentNode.nowrap = false;
  369. rName = rLink.innerHTML;
  370. rId = rLink.href.toString().split('=')[2];
  371. if (requesterIndex.indexOf(rId) != -1 && location.href.indexOf(rId) == -1) {
  372. newElement = document.createElement('a');
  373. newElement.innerHTML = "&nbsp;<a style='font-size:80%;' href='javascript:unblockRequester(\""+rId+"\",\""+rName+"\");' title='Unblock this requester'>unblock</a>";
  374. rLink.parentNode.insertBefore(newElement, rLink.nextSibling);
  375. hideHIT(rLink);
  376. numBlocked+=1;
  377. } else {
  378. newElement = document.createElement('a');
  379. newElement.innerHTML = "&nbsp;<a href='javascript:blockRequester(\""+rId+"\","+i+");' style='font-size:80%;' title='Block this requester'>x</a>";
  380. rLink.parentNode.insertBefore(newElement, rLink.nextSibling);
  381. }
  382. }
  383. return numBlocked;
  384. }
  385.  
  386. unsafeWindow.unhideAllHITs = function () {
  387. theseRequesters = document.evaluate("//a[starts-with(@href,'/mturk/searchbar?selectedSearchType=hitgroups&requesterId=')]",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
  388. for (i=0; i<theseRequesters.snapshotLength; i++) {
  389. unhideHIT(theseRequesters.snapshotItem(i));
  390. }
  391. }
  392.  
  393. function showNumBlocked(numBlocked) {
  394. collapseAll = document.getElementById('collapseall');
  395. showAllBlocked = document.createElement("span");
  396. showAllBlocked.innerHTML = '&nbsp;&nbsp;<font color="#9ab8ef">|</font>&nbsp;&nbsp;<a href="javascript:unhideAllHITs();" class="footer_links" id="showblocked">Show ' + numBlocked + ' Blocked</a>';
  397. collapseAll.parentNode.insertBefore(showAllBlocked, collapseAll.nextSibling);
  398. }
  399.  
  400.  
  401.  
  402.  
  403. unsafeWindow.blockRequester = function (rId,i) {
  404. rName = theseRequesters.snapshotItem(i).innerHTML;
  405. rEntry = rId+"::"+rName;
  406. requesterIndex+= rEntry+"}{";
  407. if (confirm("Hide HITs from "+rName+" ("+rId+")?")) {
  408. window.setTimeout(function() {
  409. GM_setValue("requesterIndex", requesterIndex);
  410. GM_setValue("requesterUpdated", "Blocked,"+rEntry);
  411. }, 0);
  412. //window.setTimeout(GM_setValue, 0, "requesterIndex", requesterIndex);
  413. //window.setTimeout(GM_setValue, 0, "requesterUpdated", "Blocked,"+rEntry);
  414.  
  415.  
  416. document.location.reload();
  417. }
  418. }
  419.  
  420. unsafeWindow.unblockRequester = function (rId,rName) {
  421. theseRequesters = document.evaluate("//a[starts-with(@href,'/mturk/searchbar?selectedSearchType=hitgroups&requesterId=')]",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
  422. rEntry = rId+"::"+rName;
  423. half = requesterIndex.split(rId+"::");
  424. left = half[0];
  425. temp = half[1].split('}{');
  426. right = temp[1]+"}{";
  427. if (temp.length>1) {
  428. for (i=2;i<temp.length-1;i++) {
  429. right+=temp[i]+"}{";
  430. }
  431. }
  432. requesterIndex = left + right;
  433. window.setTimeout(function() {
  434. GM_setValue("requesterIndex", requesterIndex);
  435. GM_setValue("requesterUpdated", "Unblocked,"+rEntry);
  436. }, 0);
  437. //window.setTimeout(GM_setValue, 0, "requesterIndex", requesterIndex);
  438. //window.setTimeout(GM_setValue, 0, "requesterUpdated", "Unblocked,"+rEntry);
  439. document.location.reload();
  440. }
  441.  
  442. function addGlobalStyle(css) {
  443. head = document.getElementsByTagName('head')[0];
  444. if (!head) { return; }
  445. style = document.createElement('style');
  446. style.type = 'text/css';
  447. style.innerHTML = css;
  448. head.appendChild(style);
  449. }
  450.  
  451. addGlobalStyle('.blocked { display: none; }');
  452. showUpdates();
  453. showNumBlocked(hideMatchingHITs());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement