JR mturk timer warning

Script will warn you at specific times left for your hit. The times can be set in the options menu.

当前为 2016-06-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name JR mturk timer warning
  3. // @version 0.7.6
  4. // @namespace https://greasyfork.org/users/6406
  5. // @description Script will warn you at specific times left for your hit. The times can be set in the options menu.
  6. // @author John Ramirez (JohnnyRS)
  7. // @include http*://*.mturk.com/mturk/continue*
  8. // @include http*://*.mturk.com/mturk/accept*
  9. // @include http*://*.mturk.com/mturk/preview*
  10. // @include http*://*.mturk.com/mturk/myhits*
  11. // @include http*://*.mturk.com/mturk/submit*
  12. // @exclude *mturk.com/*HITMONITOR*
  13. // @grant GM_getValue
  14. // @grant GM_setValue
  15. // ==/UserScript==
  16.  
  17. // Warns you with a voice, alarm or colors on the amount of time left for the current hit. You can set your own options
  18. // in the menu at top. There is a male and female voice for the warning. You can turn off the warnings and color.
  19. // the options are saved so you don't have to set it again. You can stop it saving options for the current hit if
  20. // you just want changes for the hit you are on.
  21.  
  22. var gSeconds = 0, gElapsedSeconds = 0, gWorking = false, gDoNotSpeak = false, gVolume = 1;
  23. var gOptions = {"status":["On",0],"voice":["female",0],"alarm":["Off",0],"color":["On",0]};
  24. var gOptionTimes = {"60":["Off",0],"30":["On",0],"20":["Off",0],"10":["Off",0],"5":["On",0],"1":["On",0],"30s":["On",0]};
  25. var gWarningTimes = {"60":false,"30":false,"20":false,"10":false,"5":false,"1":false,"30s":false};
  26. var gHtmlColors = ["FF0000","FF3322","FF6633","FFAA39","FFCCCC","FFEFEC","FFEFCC","EEEFCC","CCCCBB","CCCCBF","CCCCCC","CCCCDD","CCCCDF","CCCCEE","CCCCEF","CCDDFF","DDDDFF","EEEEFF","EEEEF9","EEEEF6","FFFFF2","FFFFF5","FFFFF8","FFFFFF"];
  27.  
  28. var f60MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%201%20hour%20left%20-%20Laura.mp3");
  29. var m60MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%201%20hour%20left%20-%20Paul.mp3");
  30. var a60MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/Alarm%2060%20minutes%20left.mp3");
  31. var f30MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%2030%20minutes%20left%20-%20laura.mp3");
  32. var m30MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%2030%20minutes%20left%20-%20Paul.mp3");
  33. var a30MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/Alarm%2030%20minutes%20left.mp3");
  34. var f20MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%2020%20minutes%20left%20-%20laura.mp3");
  35. var m20MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%2020%20minutes%20left%20-%20Paul.mp3");
  36. var a20MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/Alarm%2020%20minutes%20left.mp3");
  37. var f10MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%2010%20minutes%20left%20-%20Laura.mp3");
  38. var m10MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%2010%20minutes%20left%20-%20Paul.mp3");
  39. var a10MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/Alarm%2010%20minutes%20left.mp3");
  40. var f5MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%205%20minutes%20left%20-%20Laura.mp3");
  41. var m5MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%205%20minutes%20left%20-%20Paul.mp3");
  42. var a5MinutesLeft = new Audio("http://www.allbyjohn.com/sounds/Alarm%205%20minutes%20left.mp3");
  43. var f1MinuteLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%201%20minute%20left%20-%20Laura.mp3");
  44. var m1MinuteLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%201%20minute%20left%20-%20Paul.mp3");
  45. var a1MinuteLeft = new Audio("http://www.allbyjohn.com/sounds/Alarm%201%20minute%20left.mp3");
  46. var f30SecondsLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%2030%20seconds%20left%20-%20Laura.mp3");
  47. var m30SecondsLeft = new Audio("http://www.allbyjohn.com/sounds/You%20have%20less%20than%2030%20seconds%20left%20-%20Paul.mp3");
  48. var a30SecondsLeft = new Audio("http://www.allbyjohn.com/sounds/Alarm%2030%20seconds%20left.mp3");
  49. var fTesting = new Audio("http://www.allbyjohn.com/sounds/This%20is%20just%20a%20test%20of%20this%20warning%20system%20-%20Laura.mp3");
  50. var mTesting = new Audio("http://www.allbyjohn.com/sounds/This%20is%20just%20a%20test%20of%20this%20warning%20system%20-%20Paul.mp3");
  51. var g60MinutesLeft = null, g30MinutesLeft = null, g20MinutesLeft = null, g10MinutesLeft = null, g5MinutesLeft = null, g1MinutesLeft = null,
  52. g30SecondsLeft = null, gTesting = null;
  53.  
  54. function loadSettings() {
  55. gOptions = JSON.parse(GM_getValue("JR_WN_options",JSON.stringify(gOptions)));
  56. gOptionTimes = JSON.parse(GM_getValue("JR_WN_optionTimes",JSON.stringify(gOptionTimes)));
  57. }
  58. function saveSettings() {
  59. GM_setValue("JR_WN_options",JSON.stringify(gOptions));
  60. GM_setValue("JR_WN_optionTimes",JSON.stringify(gOptionTimes));
  61. }
  62. function pad(number, length) {
  63. var str = '' + number;
  64. while (str.length < length) {
  65. str = '&nbsp;' + str;
  66. }
  67. return str;
  68. }
  69. function createMyElement(elementName,theClass,theId,theStyle,theText) {
  70. var theElement = document.createElement(elementName);
  71. if (theClass) theElement.className = theClass;
  72. if (theId) theElement.id = theId;
  73. if (theStyle) theElement.setAttribute("style",theStyle);
  74. if (theText) theElement.innerHTML = theText;
  75. return theElement;
  76. }
  77. function createButton(theClass,theId,theValue,theName,theStyle) {
  78. var theButton = createMyElement("input",theClass,theId,theStyle);
  79. theButton.type = "button";
  80. if (theValue) theButton.value = theValue;
  81. if (theName) theButton.name = theName;
  82. return theButton;
  83. }
  84. function createCheckbox(theClass,theId,theValue,theName,theStyle) {
  85. var theCheckbox = createMyElement("input",theClass,theId,theStyle);
  86. theCheckbox.value = theValue;
  87. theCheckbox.type = "checkbox";
  88. if (theName) theCheckbox.name = theName;
  89. return theCheckbox;
  90. }
  91. function createTextInput(theClass,theId,theValue,theName,theStyle) {
  92. var theInput = createMyElement("input",theClass,theId,theStyle);
  93. theInput.type = "text";
  94. if (theValue) theInput.value = theValue;
  95. if (theName) theInput.name = theName;
  96. return theInput;
  97. }
  98. function setUpVoices(gender) {
  99. if (gender == "Female") {
  100. g60MinutesLeft = f60MinutesLeft; g30MinutesLeft = f30MinutesLeft; g20MinutesLeft = f20MinutesLeft; g10MinutesLeft = f10MinutesLeft;
  101. g5MinutesLeft = f5MinutesLeft; g1MinuteLeft = f1MinuteLeft; g30SecondsLeft = f30SecondsLeft; gTesting = fTesting;
  102. } else if (gender == "Male") {
  103. g60MinutesLeft = m60MinutesLeft; g30MinutesLeft = m30MinutesLeft; g20MinutesLeft = m20MinutesLeft; g10MinutesLeft = m10MinutesLeft;
  104. g5MinutesLeft = m5MinutesLeft; g1MinuteLeft = m1MinuteLeft; g30SecondsLeft = m30SecondsLeft; gTesting = mTesting;
  105. } else {
  106. g60MinutesLeft = a60MinutesLeft; g30MinutesLeft = a30MinutesLeft; g20MinutesLeft = a20MinutesLeft; g10MinutesLeft = a10MinutesLeft;
  107. g5MinutesLeft = a5MinutesLeft; g1MinuteLeft = a1MinuteLeft; g30SecondsLeft = a30SecondsLeft; gTesting = a30SecondsLeft;
  108. }
  109. }
  110. function setColor(theTimeLeft) {
  111. var theColor = "FFFFFF";
  112. if (theTimeLeft<30) theColor = gHtmlColors[0]; // less than 30 seconds
  113. else if (theTimeLeft<60) theColor = gHtmlColors[1]; // less than 1 minute
  114. else if (theTimeLeft<600) {
  115. theColor = gHtmlColors[Math.ceil(theTimeLeft/60)]; // less than 10 minutes
  116. }
  117. else if (theTimeLeft<1200) {
  118. theColor = gHtmlColors[Math.ceil((theTimeLeft-600)/120)+10]; // less than 20 minutes
  119. }
  120. else if (theTimeLeft<1800) {
  121. theColor = gHtmlColors[Math.ceil((theTimeLeft-1200)/240)+15]; // less than 30 minutes
  122. }
  123. else if (theTimeLeft<2100) theColor = gHtmlColors[20];
  124. else if (theTimeLeft<2400) theColor = gHtmlColors[21];
  125. else if (theTimeLeft<3000) theColor = gHtmlColors[22];
  126. else if (theTimeLeft<2600) theColor = gHtmlColors[23];
  127.  
  128. document.getElementsByTagName("form")[1].style.backgroundColor = "#"+theColor;
  129. }
  130. function timeLeft() {
  131. theTime = document.getElementById("theTime");
  132. if (theTime) {
  133. var theSplit = theTime.innerHTML.split(":");
  134. hours = parseInt(theSplit[0]);
  135. minutes = parseInt(theSplit[1]);
  136. seconds = parseInt(theSplit[2]);
  137. minutes += hours * 60;
  138. gElapsedSeconds = seconds + (minutes * 60);
  139. var timeLeftMinutes = Math.floor(gSeconds/60) - minutes - 1;
  140. document.getElementById("timeLeftDiv").innerHTML = "Time Left: " + timeLeftMinutes + " Minutes : " + (60-seconds) + " Seconds";
  141. return gSeconds - gElapsedSeconds;
  142. } else return null;
  143. }
  144. function warning(theSound,theTime) {
  145. theSound.volume = gVolume;
  146. theSound.play();
  147. gWarningTimes[theTime] = true;
  148. }
  149. function checkTimes(announceNow) {
  150. var timeLeftSeconds = timeLeft();
  151. var timeLeftMinutes = Math.floor(timeLeftSeconds/60);
  152.  
  153.  
  154. if (timeLeftSeconds) {
  155. if (timeLeftSeconds<=30) {
  156. if (gOptionTimes["30s"][0] == "On" && !gWarningTimes["30s"]) warning(g30SecondsLeft,"30s");
  157. } else if (timeLeftSeconds<=60) {
  158. if (gOptionTimes["1"][0] == "On" && !gWarningTimes["1"]) warning(g1MinuteLeft,"1");
  159. } else if (timeLeftMinutes<5 && (timeLeftMinutes>3 || announceNow)) {
  160. if (gOptionTimes["5"][0] == "On" && (!gWarningTimes["5"] || announceNow))
  161. if (gElapsedSeconds>185 || announceNow) warning(g5MinutesLeft,"5");
  162. } else if (timeLeftMinutes<10 && (timeLeftMinutes>7 || announceNow)) {
  163. if (gOptionTimes["10"][0] == "On" && (!gWarningTimes["10"] || announceNow))
  164. if (gElapsedSeconds>185 || announceNow) warning(g10MinutesLeft,"10");
  165.  
  166. } else if (timeLeftMinutes<20 && (timeLeftMinutes>15 || announceNow)) {
  167. if (gOptionTimes["20"][0] == "On" && (!gWarningTimes["20"] || announceNow))
  168. if (gElapsedSeconds>305 || announceNow) warning(g20MinutesLeft,"20");
  169. } else if (timeLeftMinutes<30 && (timeLeftMinutes>24 || announceNow)) {
  170. if (gOptionTimes["30"][0] == "On" && (!gWarningTimes["30"] || announceNow))
  171. if (gElapsedSeconds>365 || announceNow) warning(g30MinutesLeft,"30");
  172. } else if (timeLeftMinutes<60 && (timeLeftMinutes>53 || announceNow)) {
  173. if (gOptionTimes["60"][0] == "On" && (!gWarningTimes["60"] || announceNow))
  174. if (gElapsedSeconds>425 || announceNow) warning(g60MinutesLeft,"60");
  175. }
  176. if (gOptions.color[0] == "On") setColor(timeLeftSeconds);
  177. else document.getElementsByTagName("form")[1].style.backgroundColor = "#FFFFFF";
  178. }
  179. }
  180. function setOptions() {
  181. gOptions.status[0] = document.getElementById("warningOption").getAttribute("currentValue");
  182. gOptions.status[1] = document.getElementById("warningOption").getAttribute("valueIndex");
  183. gOptions.voice[0] = document.getElementById("warningVoiceOptions").getAttribute("currentValue");
  184. gOptions.voice[1] = document.getElementById("warningVoiceOptions").getAttribute("valueIndex");
  185. gOptions.alarm[0] = document.getElementById("warningAlarmOptions").getAttribute("currentValue");
  186. gOptions.alarm[1] = document.getElementById("warningAlarmOptions").getAttribute("valueIndex");
  187. gOptions.color[0] = document.getElementById("warningColorOptions").getAttribute("currentValue");
  188. gOptions.color[1] = document.getElementById("warningColorOptions").getAttribute("valueIndex");
  189. gOptionTimes["60"][0] = document.getElementById("1HourOptions").getAttribute("currentValue");
  190. gOptionTimes["60"][1] = document.getElementById("1HourOptions").getAttribute("valueIndex");
  191. gOptionTimes["30"][0] = document.getElementById("30MinutesOptions").getAttribute("currentValue");
  192. gOptionTimes["30"][1] = document.getElementById("30MinutesOptions").getAttribute("valueIndex");
  193. gOptionTimes["20"][0] = document.getElementById("20MinutesOptions").getAttribute("currentValue");
  194. gOptionTimes["20"][1] = document.getElementById("20MinutesOptions").getAttribute("valueIndex");
  195. gOptionTimes["10"][0] = document.getElementById("10MinutesOptions").getAttribute("currentValue");
  196. gOptionTimes["10"][1] = document.getElementById("10MinutesOptions").getAttribute("valueIndex");
  197. gOptionTimes["5"][0] = document.getElementById("5MinutesOptions").getAttribute("currentValue");
  198. gOptionTimes["5"][1] = document.getElementById("5MinutesOptions").getAttribute("valueIndex");
  199. gOptionTimes["1"][0] = document.getElementById("1MinuteOptions").getAttribute("currentValue");
  200. gOptionTimes["1"][1] = document.getElementById("1MinuteOptions").getAttribute("valueIndex");
  201. gOptionTimes["30s"][0] = document.getElementById("30SecondsOptions").getAttribute("currentValue");
  202. gOptionTimes["30s"][1] = document.getElementById("30SecondsOptions").getAttribute("valueIndex");
  203. if (gOptions.voice[0] != "Off") setUpVoices(gOptions.voice[0]);
  204. else if (gOptions.alarm[0] != "Off") setUpVoices();
  205. if (gWorking) {
  206. if (gOptions.color[0] == "On" && gOptions.status[0] == "On") setColor(timeLeft());
  207. else document.getElementsByTagName("form")[1].style.backgroundColor = "#FFFFFF";
  208. if (!gDoNotSpeak && gOptions.status[0] == "On" && (gOptions.voice[0] != "Off" || gOptions.alarm[0] != "Off")) checkTimes(true);
  209. } else if (gOptions.status[0] == "On" && (gOptions.voice[0] != "Off" || gOptions.alarm[0] != "Off") && !gDoNotSpeak) gTesting.play();
  210. if (document.getElementById("warningOptionsSave").checked) saveSettings();
  211. }
  212. function createSpanOptions(theNode,theOptions) {
  213. var theId = "", theText = "", theValues = [], theStatus = "", replaceWith="";
  214. for (var i=0,len=theOptions.length; i<len; i++) {
  215. theId = theOptions[i][0];
  216. theText = theOptions[i][1];
  217. theValues = theOptions[i][2];
  218. theStatus = theValues[theOptions[i][3]].substr(0,1);
  219. replaceWith = theValues[theOptions[i][3]].replace(theStatus,"");
  220. theOption = createMyElement("span","myOwnSpan",theId,
  221. "cursor:pointer; -moz-user-select: -moz-none; -khtml-user-select: none; -webkit-user-select: none;",
  222. theText.replace("$",replaceWith));
  223. if (theStatus=="-") theOption.style.color = "#FF0000";
  224. else theOption.style.color = "#006600";
  225. theOption.setAttribute("theValues",JSON.stringify(theValues));
  226. theOption.setAttribute("valueIndex",theOptions[i][3]);
  227. theOption.setAttribute("theText",theText);
  228. theOption.setAttribute("currentValue",replaceWith);
  229. theNode.appendChild(document.createTextNode(" "));
  230. theNode.appendChild(theOption);
  231. theOption.onmousemove = function(e) {
  232. e.preventDefault();
  233. e.stopPropagation();
  234. return false;
  235. }
  236. theOption.onclick = function() {
  237. gDoNotSpeak = false;
  238. var theValues = JSON.parse(this.getAttribute("theValues"));
  239. var theIndex = parseInt(this.getAttribute("valueIndex"));
  240. var theText = this.getAttribute("theText");
  241. theIndex = (theIndex < theValues.length-1) ? theIndex+1 : 0;
  242. this.setAttribute("valueIndex",theIndex);
  243. var theStatus = theValues[theIndex].substr(0,1);
  244. var replaceWith = theValues[theIndex].replace(theStatus,"");
  245. this.innerHTML = theText.replace("$",replaceWith);
  246. this.setAttribute("currentValue",replaceWith);
  247. if (theStatus=="-") this.style.color = "#FF0000";
  248. else this.style.color = "#006600";
  249. if (this.id == "warningAlarmOptions" && replaceWith == "On") {
  250. document.getElementById("warningVoiceOptions").setAttribute("currentValue","Off");
  251. document.getElementById("warningVoiceOptions").setAttribute("valueIndex","1");
  252. document.getElementById("warningVoiceOptions").innerHTML = "[ Voice: Off ]";
  253. document.getElementById("warningVoiceOptions").style.color = "#FF0000";
  254. } else if (this.id == "warningVoiceOptions" && replaceWith != "Off") {
  255. document.getElementById("warningAlarmOptions").setAttribute("currentValue","Off");
  256. document.getElementById("warningAlarmOptions").setAttribute("valueIndex","0");
  257. document.getElementById("warningAlarmOptions").innerHTML = "[ Alarm: Off ]";
  258. document.getElementById("warningAlarmOptions").style.color = "#FF0000";
  259. } else if (this.id == "warningOption" && replaceWith == "Off") {
  260. gDoNotSpeak = true;
  261. } else if (this.id == "warningColorOptions") gDoNotSpeak = true;
  262. setOptions();
  263. };
  264. }
  265. }
  266. function showOptions(beforeNode) {
  267. window.addEventListener("load", function(){
  268. var theOptionsContainer = createMyElement("div","myOwnDiv","warningOptionsContainer",
  269. "background-color:#D8FCFB; text-align:center; margin:0 auto; padding: 0; width:80%; border: 2px solid black;");
  270. var theOptionsToggle = createMyElement("div","myOwnDiv","warningOptionsToggle","margin:0; padding:0 0 2px 0; background-color:#696969; color: Aqua; font-size:10px; cursor:default;",
  271. "Click here for Time Left Warning options.");
  272. var theOptionsControl = createMyElement("div","myOwnDiv","warningOptionsController","display:none;");
  273. var theOptionsSave = createCheckbox("myOwnCheckBox","warningOptionsSave","save Me","","margin-left:20px; height:10px;");
  274. theOptionsSave.checked = true;
  275. theOptionsSave.onclick = function() { if (theOptionsSave.checked) saveSettings(); }
  276. var spanWarningOptions = [ ["warningOption","[ Status: $ ]",["+On","-Off"],gOptions.status[1]], ["warningVoiceOptions","[ Voice: $ ]",["+Female","-Off","+Male"],gOptions.voice[1]],
  277. ["warningAlarmOptions","[ Alarm: $ ]",["-Off","+On"],gOptions.alarm[1]], ["warningColorOptions","[ Color: $ ]",["+On","-Off"],gOptions.color[1]]];
  278. theOptionsControl.appendChild(document.createTextNode("Time Left Warning:"));
  279. createSpanOptions(theOptionsControl,spanWarningOptions);
  280. theOptionsControl.appendChild(theOptionsSave);
  281. theOptionsControl.appendChild(document.createTextNode(" Save Options"));
  282. theOptionsControl.appendChild(createMyElement("br"));
  283. theOptionsControl.appendChild(document.createTextNode("Warn at: "));
  284. var spanTimeOptions = [ ["30SecondsOptions","[30 seconds]",["+On","-Off"],gOptionTimes["30s"][1]], ["1MinuteOptions","[1 minute]",["+On","-Off"],gOptionTimes["1"][1]],
  285. ["5MinutesOptions","[5 minutes]",["+On","-Off"],gOptionTimes["5"][1]], ["10MinutesOptions","[10 minutes]",["-Off","+On"],gOptionTimes["10"][1]],
  286. ["20MinutesOptions","[20 minutes]",["-Off","+On"],gOptionTimes["20"][1]], ["30MinutesOptions","[30 minutes]",["+On","-Off"],gOptionTimes["30"][1]],
  287. ["1HourOptions","[1 hour]",["-Off","+On"],gOptionTimes["60"][1]]];
  288. createSpanOptions(theOptionsControl,spanTimeOptions);
  289. theOptionsControl.appendChild(createMyElement("br"));
  290. theOptionsControl.appendChild(document.createTextNode("Click on text above to change options."));
  291. var volumeLower = createMyElement("span","myOwnSpan","lowerVolumeControl",
  292. "cursor: pointer; margin-left:20px; -moz-user-select: -moz-none; -khtml-user-select: none; -webkit-user-select: none;","<-");
  293. theOptionsControl.appendChild(volumeLower);
  294. var volumeLevelText = createMyElement("span","myOwnSpan","theVolumeText",
  295. "cursor:pointer; display: inline-block; width:110px; -moz-user-select: -moz-none; -khtml-user-select: none; -webkit-user-select: none;",
  296. " Volume Level: 100 ");
  297. theOptionsControl.appendChild(volumeLevelText);
  298. var volumeHigher = createMyElement("span","myOwnSpan","lowerVolumeControl",
  299. "cursor: pointer; -moz-user-select: -moz-none; -khtml-user-select: none; -webkit-user-select: none;","->");
  300. theOptionsControl.appendChild(volumeHigher);
  301. volumeLower.onclick = function() {
  302. gVolume = (gVolume<0.1) ? 0 : (gVolume-0.1);
  303. document.getElementById("theVolumeText").innerHTML = " Volume Level: " + pad(Math.round(gVolume*100),3);
  304. }
  305. volumeHigher.onclick = function() {
  306. gVolume = (gVolume>0.9) ? 1 : (gVolume+0.1);
  307. document.getElementById("theVolumeText").innerHTML = " Volume Level: " + pad(Math.round(gVolume*100),3);
  308. }
  309. theOptionsToggle.onclick = function() {
  310. var theDisplay = theOptionsControl.style.display;
  311. theOptionsControl.style.display = (theDisplay == "none") ? "block" : "none";
  312. if (theOptionsControl.style.display == "none") this.innerHTML = "Click here for Time Left Warning options menu.";
  313. else this.innerHTML = "Click here to hide the options menu";
  314. }
  315. theOptionsContainer.appendChild(theOptionsToggle);
  316. theOptionsContainer.appendChild(theOptionsControl);
  317. beforeNode.parentNode.insertBefore(theOptionsContainer,beforeNode);
  318. }, false);
  319. }
  320. function getTimeLeft(theTime) {
  321. if (theTime) {
  322. var tempArray = (theTime.indexOf("second") != -1) ? theTime.split("second")[0].trim().split(" ") : null;
  323. var seconds = (tempArray) ? tempArray[tempArray.length-1] : "0";
  324. tempArray = (theTime.indexOf("minute") != -1) ? theTime.split("minute")[0].trim().split(" ") : null;
  325. var minutes = (tempArray) ? tempArray[tempArray.length-1] : "0";
  326. tempArray = (theTime.indexOf("hour") != -1) ? theTime.split("hour")[0].trim().split(" ") : null;
  327. var hours = (tempArray) ? tempArray[tempArray.length-1] : "0";
  328. tempArray = (theTime.indexOf("day") != -1) ? theTime.split("day")[0].trim().split(" ") : null;
  329. var days = (tempArray) ? tempArray[tempArray.length-1] : "0";
  330. tempArray = (theTime.indexOf("week") != -1) ? theTime.split("week")[0].trim().split(" ") : null;
  331. var weeks = (tempArray) ? tempArray[tempArray.length-1] : "0";
  332. return( {"weeks":weeks,"days":days,"hours":hours,"minutes":minutes,"seconds":seconds} );
  333. } else return null;
  334. }
  335.  
  336. loadSettings();
  337. setUpVoices(gOptions.voice[0]);
  338. var timerTextNode = document.getElementsByClassName("title_orange_text")[0];
  339. if (timerTextNode && timerTextNode.innerHTML.indexOf("Timer:") != -1) {
  340. gWorking = true;
  341. var weeks = 0, days = 0, hours = 0, minutes = 0;
  342. var theTime = document.getElementById("theTime");
  343. var timeLeftNode = createMyElement("div","myOwnDiv","timeLeftDiv","padding-left:20px");
  344. theTime.parentNode.parentNode.parentNode.appendChild(timeLeftNode);
  345. var ofTime = timerTextNode.innerHTML.split("</span>")[1];
  346. var ofTime = ofTime.split("<noscript>")[0].replace(/\s\s+/g," ").trim();
  347. var realOfTime = ofTime.replace("of ","").trim();
  348. var theTimeLeft = getTimeLeft(realOfTime);
  349. if (theTimeLeft) {
  350. days = parseInt(theTimeLeft.weeks*7); console.log("days: " + days);
  351. hours = parseInt(theTimeLeft.days*24) + parseInt(days*24); console.log("hours: " + hours);
  352. minutes = parseInt(theTimeLeft.hours*60) + parseInt(hours*60); console.log("minutes: " + minutes + " and " + theTimeLeft.minutes);
  353. gSeconds = parseInt(theTimeLeft.minutes*60) + parseInt(minutes*60); console.log("seconds: " + gSeconds);
  354. var intervalVar = setInterval( function(){
  355. if (gOptions.status[0] == "On" && (gOptions.voice[0] != "Off" || gOptions.alarm[0] != "Off")) checkTimes();
  356. else if (gOptions.status[0] == "On") timeLeft();
  357. }, 4000);
  358. var theHitForm = document.getElementsByTagName("form")[1];
  359. var theTable = theHitForm.getElementsByTagName("table")[0];
  360. var theDiv = theHitForm.getElementsByTagName("div")[2];
  361. var theIframe = theHitForm.getElementsByTagName("iframe")[0];
  362. theTable.style.backgroundColor = "#FFFFFF";
  363. if (theDiv) theDiv.style.backgroundColor = "#FFFFFF";
  364. if (theIframe) theIframe.style.backgroundColor = "#FFFFFF";
  365. showOptions(theHitForm);
  366. if (gOptions.color[0] == "On" && gOptions.status[0] == "On") setColor(timeLeft());
  367. else document.getElementsByTagName("form")[1].style.backgroundColor = "#FFFFFF";
  368. }
  369. } else {
  370. var theAlertBox = document.getElementById("alertBox");
  371. var theErrorTitle = document.getElementsByClassName("error_title")[0];
  372. var beforeNode = (theErrorTitle) ? theErrorTitle.parentNode.parentNode.parentNode : (theAlertBox) ? theAlertBox : timerTextNode.parentNode.parentNode.parentNode;
  373. showOptions(beforeNode);
  374. }