HIT Scraper to MTurk Suite

Does things...

  1. // ==UserScript==
  2. // @name HIT Scraper to MTurk Suite
  3. // @namespace https://github.com/Kadauchi
  4. // @version 1.0.0
  5. // @description Does things...
  6. // @author Kadauchi
  7. // @icon http://i.imgur.com/oGRQwPN.png
  8. // @include https://www.mturk.com/hitscraper-to-mturk-suite
  9. // @include https://worker.mturk.com/hitscraper-to-mturk-suite
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. const bl = window.localStorage.getItem(`scraper_ignore_list`)
  14. const il = window.localStorage.getItem(`scraper_include_list`)
  15.  
  16. if (bl || il) {
  17. document.body.innerHTML = ``
  18.  
  19. if (bl) {
  20. const blockList = convertBlockList(bl)
  21. saveToFileJSON(`block-list`, blockList)
  22. }
  23. if (il) {
  24. const includeList = convertIncludeList(il)
  25. saveToFileJSON(`include-list`, includeList)
  26. }
  27. } else {
  28. document.body.innerHTML = `No HIT Scraper Block or Include Lists found`
  29. }
  30. })()
  31.  
  32. function convertBlockList () {
  33. const [list] = arguments
  34.  
  35. const mturkSuite = {}
  36. const hitScraper = list.split(`^`)
  37.  
  38. for (const value of hitScraper) {
  39. mturkSuite[value] = {
  40. name: value,
  41. match: value,
  42. strict: true
  43. }
  44. }
  45.  
  46. return mturkSuite
  47. }
  48.  
  49. function convertIncludeList () {
  50. const [list] = arguments
  51.  
  52. const mturkSuite = {}
  53. const hitScraper = list.split(`^`)
  54.  
  55. for (const value of hitScraper) {
  56. mturkSuite[value] = {
  57. name: value,
  58. match: value,
  59. strict: true,
  60. sound: true,
  61. alarm: false,
  62. pushbullet: false,
  63. notification: true
  64. }
  65. }
  66.  
  67. return mturkSuite
  68. }
  69.  
  70. function saveToFileJSON () {
  71. const [name, json] = arguments
  72.  
  73. const today = new Date()
  74. const month = today.getMonth() + 1
  75. const day = today.getDate()
  76. const year = today.getFullYear()
  77. const date = `${year}${month < 10 ? `0` : ``}${month}${day < 10 ? `0` : ``}${day}`
  78.  
  79. const data = JSON.stringify(json)
  80.  
  81. const exportFile = document.createElement(`a`)
  82. exportFile.href = window.URL.createObjectURL(new window.Blob([data], { type: `application/json` }))
  83. exportFile.download = `scraper-to-mts-backup-${date}-${name}.json`
  84. exportFile.textContent = `scraper-to-mts-backup-${date}-${name}.json`
  85.  
  86. document.body.appendChild(exportFile)
  87. document.body.appendChild(document.createElement(`br`))
  88. }