General: Requester ID

Displays the Requester ID in the dashboard and HIT search.

  1. // ==UserScript==
  2. // @name General: Requester ID
  3. // @description Displays the Requester ID in the dashboard and HIT search.
  4. // @include https://www.mturk.com/mturk/statusdetail*
  5. // @include http://*.mturk.com/*
  6. // @include https://*.mturk.com/*
  7. // @version 1
  8. // @namespace https://greasyfork.org/users/6438
  9. // ==/UserScript==
  10.  
  11. function getFirstRequesterAnchor(str) {
  12. var ra = getRequesterAnchors();
  13. for (var i = 0; i < ra.length; i++) {
  14. if (ra[i].href.match(str)) {
  15. return ra[i];
  16. }
  17. }
  18. return null;
  19. }
  20.  
  21. function insertAttrsHTML(n,requesterID) {
  22. var parent = n.parentNode;
  23. if (parent!=null) {
  24. var stuff = "<br />";
  25. stuff += requesterID;
  26. parent.innerHTML = parent.innerHTML + stuff;
  27. }
  28. }
  29.  
  30. function parseAndInsert(n,k) {
  31. var requesterID = requesterIds[k];
  32. insertAttrsHTML(n, requesterID);
  33. }
  34.  
  35. function getRequesterAnchors() {
  36. var anchors = document.getElementsByTagName("a");
  37. var requesterAnchors = new Array;
  38. for (var i = 0; i < anchors.length; i++) {
  39. var href = anchors[i].getAttribute('href');
  40. if (href!=null) {
  41. if ((href.match("requesterId")) && !(anchors[i].innerHTML.match("Contact the Requester of this HIT")) && !(href.match("signature")) || ((href.match("requesterId") && (window.location.toString().match("statusdetail"))))) {
  42. requesterAnchors.push(anchors[i]);
  43. }
  44. }
  45. }
  46. return requesterAnchors;
  47. }
  48.  
  49. function getRequesterList() {
  50. var anchors = document.getElementsByTagName("a");
  51. for (var i = 0; i < anchors.length; i++) {
  52. var href = anchors[i].getAttribute('href');
  53. if (anchors[i].innerHTML.match("Contact the Requester of this HIT")) {
  54. // just in case Amazon switches page, want to die nicely.
  55. try {
  56. requesterIds.push(href.split("requesterId=")[1].split("&")[0]);
  57. } catch(err) {
  58. }
  59. }
  60. var title= anchors[i].getAttribute('title');
  61. if (title==null) title="";
  62. if ((window.location.toString().match("statusdetail")) && (title=="Contact this Requester")) {
  63. // just in case Amazon switches page, want to die nicely.
  64. try {
  65. requesterIds.push(href.split("requesterId=")[1].split("&")[0]);
  66. } catch(err) {
  67. }
  68. }
  69. }
  70. }
  71.  
  72. function getCurrentHIT() {
  73. var curRequesterId=getRequesterId();
  74. if (curRequesterId!=null) {
  75. requesterIds.push(curRequesterId);
  76. }
  77. }
  78.  
  79. function getLocationData(str) {
  80. var location = window.location.toString();
  81. var splitArr = location.split(str+"=");
  82. if (splitArr.length == 1) return "";
  83. return splitArr[1].split("&")[0];
  84. }
  85.  
  86. function getRequesterId() {
  87. var requesterId=getLocationData('requesterId');
  88. if (requesterId!=null && requesterId!="") return requesterId;
  89. var forms = document.getElementsByTagName("FORM");
  90. for (var i=0; i<forms.length; i++) {
  91. var splitArr=forms[i].innerHTML.split('requesterId" value="');
  92. if (splitArr.length > 1) return splitArr[1].split('"')[0];
  93. }
  94. var location = window.location.toString();
  95. if ((location.match("preview")) || (location.match("previewandaccept")) || (location.match("accept")) || (location.match("return"))) {
  96. var splitArr = document.referrer.split("requesterId=");
  97. if (splitArr.length == 1) return null;
  98. return splitArr[1].split("&")[0].replace("#","");
  99. }
  100. return null;
  101. }
  102.  
  103. var requesterIds=new Array();
  104. var useOldData=1;
  105. var useNewData=1;
  106.  
  107. continueLoading()
  108. function continueLoading() {
  109. getRequesterList();
  110. getCurrentHIT();
  111. if (useOldData==1) {
  112. var requesterAnchors = getRequesterAnchors();
  113. for (var k = 0; k < Math.min(requesterAnchors.length,requesterIds.length); k++) {
  114. parseAndInsert(requesterAnchors[k],k);
  115. }
  116. }
  117. }
  118.  
  119.