mTurk HIT Fullscreen Crosshair CSS (as Userscript)

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

当前为 2018-02-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name mTurk HIT Fullscreen Crosshair CSS (as Userscript)
  3. // @namespace salembeats
  4. // @version 1.2
  5. // @description Userscript adapatation of code found at https://codepen.io/michaelsboost/pen/fnizu
  6. // @author Cuyler Stuwe (salembeats) using code adapted from Michael Schwartz
  7. // @include *
  8. // @grant none
  9. // @require http://code.jquery.com/jquery-3.3.1.slim.min.js
  10. // ==/UserScript==
  11.  
  12. // *****************************************************************************
  13.  
  14. function isNotMturkFrame() {
  15. return !(
  16. window !== window.top &&
  17. document.referrer.includes("worker.mturk.com/projects/")
  18. );
  19. }
  20.  
  21. if(isNotMturkFrame()) {return;}
  22.  
  23. // *****************************************************************************
  24.  
  25. const CROSSHAIR_STYLES = {
  26. DOTTED: "dotted",
  27. DASHED: "dashed",
  28. SOLID: "solid"
  29. };
  30.  
  31. const CROSSHAIR_COLORS = {
  32. BLACK: "black",
  33. RED: "red"
  34. };
  35.  
  36. // *****************************************************************************
  37. // SET UP YOUR CROSSHAIR STYLE HERE.
  38. // *****************************************************************************
  39.  
  40. const CROSSHAIR_THICKNESS_PX = 1;
  41. const CROSSHAIR_STYLE = CROSSHAIR_STYLES.DOTTED;
  42. const CROSSHAIR_COLOR = CROSSHAIR_COLORS.BLACK;
  43. SHOULD_MODIFY_POINTER_TO_CROSSHAIR_CURSOR = true;
  44.  
  45. // *****************************************************************************
  46.  
  47. document.body.insertAdjacentHTML("beforeend", `
  48. <div id="crosshair-h" class="hair"></div>
  49. <div id="crosshair-v" class="hair"></div>
  50. `);
  51.  
  52. document.head.insertAdjacentHTML("beforeend", `
  53. <style>
  54.  
  55. * {
  56. ${SHOULD_MODIFY_POINTER_TO_CROSSHAIR_CURSOR ? "cursor: crosshair !important;" : ""}
  57. }
  58.  
  59. #crosshair-h {
  60. width: 100%;
  61. }
  62.  
  63. #crosshair-v {
  64. height: 100%;
  65. }
  66.  
  67. .hair {
  68. position: fixed;
  69. top:0; left:0;
  70. margin-top: 0px; /* The offset here by the original author made zero sense. */
  71. margin-left: 0px; /* The offset here by the original author made zero sense. */
  72. background: transparent;
  73. border-top: ${CROSSHAIR_THICKNESS_PX}px ${CROSSHAIR_STYLE} #000;
  74. border-left: ${CROSSHAIR_THICKNESS_PX}px ${CROSSHAIR_STYLE} #000;
  75. pointer-events: none;
  76. z-index: ${Number.MAX_SAFE_INTEGER};
  77. }
  78. </style>
  79. `);
  80.  
  81. $(document).ready(function() {
  82.  
  83. var cH = $('#crosshair-h'),
  84. cV = $('#crosshair-v');
  85.  
  86. window.addEventListener("mousemove", e => {
  87. });
  88.  
  89. $(this).on('mousemove touchmove', function(e) {
  90.  
  91. // Original author was using pageX and pageY, but we really need clientX and clientY.
  92. cH.css('top', e.clientY);
  93. cV.css('left', e.clientX);
  94. });
  95.  
  96. });

QingJ © 2025

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