Harpocrates

Helps the Olympian scripts when they need GreaseMonkey functions

当前为 2016-09-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Harpocrates
  3. // @namespace mobiusevalon.tibbius.com
  4. // @version 0.3
  5. // @author Mobius Evalon
  6. // @description Helps the Olympian scripts when they need GreaseMonkey functions
  7. // @license Creative Commons Attribution-ShareAlike 4.0; http://creativecommons.org/licenses/by-sa/4.0/
  8. // @include /^https{0,1}:\/\/\w{0,}\.?mturk\.com.+/
  9. // @include /^https{0,1}:\/\/\w*\.amazon\.com\/ap\/signin.*(?:openid\.assoc_handle|pf_rd_i)=amzn_mturk/
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // ==/UserScript==
  13.  
  14. // use of unsafeWindow is necessary to get harpocrates into the un-sandboxed
  15. // space with the rest of the olympian scripts
  16. if(unsafeWindow.olympus === undefined) unsafeWindow.olympus = {};
  17.  
  18. unsafeWindow.olympus.harpocrates = {
  19. __12_hrs:43200000,
  20. login_timestamp:0,
  21. __init:function() {
  22. console.log("harpocrates init");
  23. if(/^https{0,1}:\/\/\w{0,}\.amazon\.com\/ap\/signin/i.test(window.location.href)) {
  24. $("#signInSubmit-input").click(function() {
  25. GM_setValue("login_timestamp",Date.now());
  26. });
  27. }
  28. else {
  29. olympus.style.add(
  30. ".red {color: #f00;}"+
  31. ".logout_time {margin-right: 4px;}"
  32. );
  33. this.login_timestamp = (GM_getValue("login_timestamp",0)*1);
  34. $("span.header_links").append(
  35. $("<br/>"),
  36. $("<b/>")
  37. .attr({
  38. "id":"harpocrates_logout_time",
  39. "title":("You logged into Mechanical Turk on "+olympus.utilities.datetime.output(this.login_timestamp,"d M \\a\\t H:i")+".\n\n"+
  40. "The cookie for Mechanical Turk expires after 12 hours, which means you will be required to login again when this timer reaches zero.")
  41. })
  42. );
  43. this.update();
  44. }
  45. },
  46. update:function() {
  47. if(olympus.harpocrates.login_timestamp > 0) {
  48. var time_left = ((olympus.harpocrates.__12_hrs-(Date.now()-olympus.harpocrates.login_timestamp))/1000);
  49. $("#harpocrates_logout_time")
  50. .attr("class",((time_left <= 3600 ? " red" : "")+(time_left <= 1800 ? " anim_pulse" : "")))
  51. .text("Time to logout: "+(time_left <= 300 ? "any moment" : olympus.utilities.dhms(time_left)));
  52. setTimeout(olympus.harpocrates.update,60000);
  53. }
  54. else $("#harpocrates_logout_time")
  55. .removeClass("red anim_pulse")
  56. .attr("title","")
  57. .text("");
  58. }
  59. };