mTurk HIT Fullscreen Crosshair CSS (as Userscript)

Userscript adapatation of code found at https://codepen.io/michaelsboost/pen/fnizu

目前為 2018-02-19 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         mTurk HIT Fullscreen Crosshair CSS (as Userscript)
// @namespace    salembeats
// @version      1.2
// @description  Userscript adapatation of code found at https://codepen.io/michaelsboost/pen/fnizu
// @author       Cuyler Stuwe (salembeats) using code adapted from Michael Schwartz
// @include      *
// @grant        none
// @require      http://code.jquery.com/jquery-3.3.1.slim.min.js
// ==/UserScript==

// *****************************************************************************

function isNotMturkFrame() {
	return !(
		window !== window.top &&
		document.referrer.includes("worker.mturk.com/projects/")
	);
}

if(isNotMturkFrame()) {return;}

// *****************************************************************************

const CROSSHAIR_STYLES = {
	DOTTED: "dotted",
	DASHED: "dashed",
	SOLID: "solid"
};

const CROSSHAIR_COLORS = {
	BLACK: "black",
	RED: "red"
};

// *****************************************************************************
// SET UP YOUR CROSSHAIR STYLE HERE.
// *****************************************************************************

const CROSSHAIR_THICKNESS_PX              = 1;
const CROSSHAIR_STYLE                     = CROSSHAIR_STYLES.DOTTED;
const CROSSHAIR_COLOR                     = CROSSHAIR_COLORS.BLACK;
SHOULD_MODIFY_POINTER_TO_CROSSHAIR_CURSOR = true;

// *****************************************************************************

document.body.insertAdjacentHTML("beforeend", `
<div id="crosshair-h" class="hair"></div>
<div id="crosshair-v" class="hair"></div>
`);

document.head.insertAdjacentHTML("beforeend", `
<style>

* {
${SHOULD_MODIFY_POINTER_TO_CROSSHAIR_CURSOR ? "cursor: crosshair !important;" : ""}
}

#crosshair-h {
width: 100%;
}

#crosshair-v {
height: 100%;
}

.hair {
position: fixed;
top:0; left:0;
margin-top: 0px; /* The offset here by the original author made zero sense. */
margin-left: 0px; /* The offset here by the original author made zero sense. */
background: transparent;
border-top: ${CROSSHAIR_THICKNESS_PX}px ${CROSSHAIR_STYLE} #000;
border-left: ${CROSSHAIR_THICKNESS_PX}px ${CROSSHAIR_STYLE} #000;
pointer-events: none;
z-index: ${Number.MAX_SAFE_INTEGER};
}
</style>
`);

$(document).ready(function() {

	var cH = $('#crosshair-h'),
		cV = $('#crosshair-v');

	window.addEventListener("mousemove", e => {
	});

	$(this).on('mousemove touchmove', function(e) {

		// Original author was using pageX and pageY, but we really need clientX and clientY.
		cH.css('top', e.clientY);
		cV.css('left', e.clientX);
	});

});