CrowdSource: Search Image URL

Click the search button to begin. Then simply click on the matching image in the google results.

  1. // ==UserScript==
  2. // @name CrowdSource: Search Image URL
  3. // @version 0.9
  4. // @namespace localhost
  5. // @description Click the search button to begin. Then simply click on the matching image in the google results.
  6. // @copyright 2013+, John Stoehr, Tjololo12, modified for Image URL Hits by BenWo
  7. // ------------------------------------------------------------------------------------
  8. // @match https://work.crowdsource.com/amt/view*
  9. // @match https://www.google.com/search*
  10. // @match https://www.google.co.uk/search*
  11. // @run-at document-end
  12. // @require http://code.jquery.com/jquery-2.1.0.js
  13. // @require https://gf.qytechs.cn/scripts/2352-parseuri-license/code/parseuri%20license.js?version=6261
  14. // ==/UserScript==
  15.  
  16. // Source: http://stackoverflow.com/a/4673436/2405722
  17. String.prototype.format = function() {
  18. var args = arguments;
  19. return this.replace(/\{(\d+)\}/g, function(match, number) {
  20. return args[number] !== undefined ? args[number] : match;
  21. });
  22. };
  23.  
  24. var mturkOrigins = ["https://work.crowdsource.com/amt/view"];
  25. var googlePrefix="https://www.google.com/search?tbm=isch&q=site:";
  26. var numTasks = 0;
  27. function isMturkOrigin(url) {
  28. for (var i = 0; i < mturkOrigins.length; ++i) {
  29. if (url.indexOf(mturkOrigins[i]) === 0) {
  30. return true;
  31. }
  32. }
  33. return false;
  34. }
  35.  
  36. function sleep(ms) {
  37. var start = new Date().getTime(), expire = start + ms;
  38. while (new Date().getTime() < expire) { }
  39. return;
  40. }
  41.  
  42. if (isMturkOrigin(location.href)) {
  43. $('label[for^=Url]').each(
  44. function() {
  45. numTasks++;
  46. $(this).append(
  47. $("<button></button>", {
  48. type: "button",
  49. text: "Search "+numTasks
  50. }).click(function() {
  51. var $task = $(this).parent().parent().prev().prev().prev().prev();
  52. var taskNumber = parseInt($(this).text().replace('Search ',''));
  53. $task.addClass("task-" + taskNumber);
  54. var textRepText = $task.text();
  55. var pageCheck = 1;
  56. var pageText = $(this).parent().parent().prev().text();
  57. if (pageText.indexOf("View Image.") > -1) {
  58. pageCheck = 0;
  59. }
  60. //console.log(pageText);
  61. var prefixKeyword = 'Keyword:';
  62. var prefixSite = 'URL:';
  63. var keywords = $.trim(textRepText.replace(prefixKeyword,'').replace(prefixSite,''));
  64. var keywordsEncoded = encodeURIComponent(keywords).replace(/%0A/g, '');
  65. //console.log(keywords);
  66. sleep(500); //added in rate limiting because issues. Should be virtually un-noticeable.
  67. window.open("https://www.google.co.uk/search?tbm=isch&q=site:{0}&magicword={1}&task={2}&isPage={3}".format(keywordsEncoded, "oogieboogie", taskNumber, pageCheck));
  68. //console.log("https://www.google.com/search?tbm=isch&q=site:{0}&magicword={1}&task={2}".format(keywordsEncoded, "oogieboogie", taskNumber));
  69. }));
  70. });
  71. console.log(numTasks+" tasks");
  72. window.addEventListener("message", function(e) {
  73. if (e.data.magicword === "oogieboogie") {
  74. console.log("Message Received");
  75. console.log(e.data);
  76. $("textarea#Url-{0}".format(e.data.task)).val(e.data.url);
  77. } else{
  78. console.log("MSG "+e.data);
  79. }
  80. }, false);
  81. } else if (window.opener != null && window.location.href.indexOf("oogieboogie") > -1) {
  82. window.opener.postMessage("Child Frame Loaded", "*");
  83. $('#rg_s div.rg_di a').each(function() {
  84. var taskNumber = parseUri(location.href).queryKey.task;
  85. var tHref = $(this).attr('href');
  86. var dHref = decodeURIComponent(tHref);
  87. // *** GET IMAGE DIRECT URL ***
  88. var refRegex = new RegExp("[\\?&]imgurl=([^&#]*)");
  89. // *** GET PAGE URL IF TASK CALLS FOR IT ***
  90. if (parseUri(location.href).queryKey.isPage == 1) {
  91. refRegex = new RegExp("[\\?&]imgrefurl=([^&#]*)");
  92. }
  93. var pageUrl = refRegex.exec(dHref)[1];
  94. $(this).click(function() {
  95. window.opener.postMessage({magicword: "oogieboogie", task: taskNumber, url: pageUrl}, "*");
  96. //console.log({magicword: "oogieboogie", task: taskNumber, url: pageUrl});
  97. //sleep(100);
  98. window.close();
  99. });
  100. });
  101. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址