HIT Scraper to MTurk Suite

Does things...

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         HIT Scraper to MTurk Suite
// @namespace    https://github.com/Kadauchi
// @version      1.0.0
// @description  Does things...
// @author       Kadauchi
// @icon         http://i.imgur.com/oGRQwPN.png
// @include      https://www.mturk.com/hitscraper-to-mturk-suite
// @include      https://worker.mturk.com/hitscraper-to-mturk-suite
// ==/UserScript==

(function () {
  const bl = window.localStorage.getItem(`scraper_ignore_list`)
  const il = window.localStorage.getItem(`scraper_include_list`)

  if (bl || il) {
    document.body.innerHTML = ``

    if (bl) {
      const blockList = convertBlockList(bl)
      saveToFileJSON(`block-list`, blockList)
    }
    if (il) {
      const includeList = convertIncludeList(il)
      saveToFileJSON(`include-list`, includeList)
    }
  } else {
    document.body.innerHTML = `No HIT Scraper Block or Include Lists found`
  }
})()

function convertBlockList () {
  const [list] = arguments

  const mturkSuite = {}
  const hitScraper = list.split(`^`)

  for (const value of hitScraper) {
    mturkSuite[value] = {
      name: value,
      match: value,
      strict: true
    }
  }

  return mturkSuite
}

function convertIncludeList () {
  const [list] = arguments

  const mturkSuite = {}
  const hitScraper = list.split(`^`)

  for (const value of hitScraper) {
    mturkSuite[value] = {
      name: value,
      match: value,
      strict: true,
      sound: true,
      alarm: false,
      pushbullet: false,
      notification: true
    }
  }

  return mturkSuite
}

function saveToFileJSON () {
  const [name, json] = arguments

  const today = new Date()
  const month = today.getMonth() + 1
  const day = today.getDate()
  const year = today.getFullYear()
  const date = `${year}${month < 10 ? `0` : ``}${month}${day < 10 ? `0` : ``}${day}`

  const data = JSON.stringify(json)

  const exportFile = document.createElement(`a`)
  exportFile.href = window.URL.createObjectURL(new window.Blob([data], { type: `application/json` }))
  exportFile.download = `scraper-to-mts-backup-${date}-${name}.json`
  exportFile.textContent = `scraper-to-mts-backup-${date}-${name}.json`

  document.body.appendChild(exportFile)
  document.body.appendChild(document.createElement(`br`))
}