Harpocrates

Helps the Olympian scripts when they need GreaseMonkey functions

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

  1. // ==UserScript==
  2. // @name Harpocrates
  3. // @namespace mobiusevalon.tibbius.com
  4. // @version 0.1
  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{0,}\.amazon\.com\/ap\/signin/
  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. get login_timestamp() {
  21. return GM_getValue("login_timestamp",0);
  22. },
  23. __init:function() {
  24. console.log("harpocrates init");
  25. if(/^https{0,1}:\/\/\w{0,}\.amazon\.com\/ap\/signin/i.test(window.location.href)) {
  26. olympus.style.add(".red {color: #f00;}");
  27. $("#signInSubmit-input").click(function() {
  28. GM_setValue("login_timestamp",Date.now());
  29. });
  30. }
  31. else this.display();
  32. },
  33. display:function() {
  34. var login_time = (this.login_timestamp*1);
  35. if(login_time > 0) {
  36. var time_left = ((this.__12_hrs-(Date.now()-login_time))/1000);
  37. $("span.header_links").append(
  38. $("<br/>"),
  39. $("<b/>")
  40. .attr("class",("logout_time"+(time_left <= 1800 ? " anim_pulse red" : "")))
  41. .text("Time to logout: "+(time_left <= 300 ? "any moment" : olympus.utilities.dhms(time_left)))
  42. );
  43. }
  44. }
  45. };