iEMB+

Makes the new iEMB more tolerable

当前为 2017-11-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name iEMB+
  3. // @namespace http://yeoxingyee.ml/
  4. // @version 1.0
  5. // @description Makes the new iEMB more tolerable
  6. // @author YXY
  7. // @match *://iemb.hci.edu.sg/*
  8. // @grant none
  9. // ==/UserScript==
  10. window.onload=function(){
  11. var link = document.createElement("link");
  12. link.href = "https://dl.dropboxusercontent.com/s/yed55pppaod34jd/iemb%2B.css";
  13. link.type = "text/css";
  14. link.rel = "stylesheet";
  15. link.id = "darkMode";
  16. var script = document.createElement("script");
  17. script.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js";
  18. if(localStorage.getItem("iEMBDark") == "1") document.getElementsByTagName("head")[0].appendChild(link);
  19. document.getElementsByTagName("head")[0].appendChild(script);
  20. var firstTime = localStorage.getItem("iEMBFirst");
  21. if(!firstTime){
  22. window.alert("Welcome to iEMB+!\nThis is a mini tutorial on how to use this script!\n(Click OK to continue)");
  23. window.alert("Firstly, the read all button will read everything! (Refresh after the reload to make sure everything's read) \nTip: 1/3");
  24. window.alert("Next, you can toggle dark/light mode by clicking the button in the top menu! \nTip: 2/3");
  25. window.alert("Lastly, change your profile picture by clicking on it! \nTip: 3/3");
  26. window.alert("And... that's it! If you have any questions / feedback contact me at \"yeoxingyee30@gmail.com\" with the subject heading of \"iEMB+ Feedback!\"\nEnjoy!");
  27. localStorage.setItem("iEMBFirst", "1");
  28. }
  29. var dp = localStorage.getItem("profilePic");
  30. if(!dp){
  31. dp = window.prompt("Profile pic not set! \n Please enter a direct link to the image that you want for your profile picture!");
  32. $('.iemb_user_left>img').attr('src', dp);
  33. localStorage.setItem("profilePic", dp);
  34. }
  35. console.log("iEMB+: Initialising...");
  36. var verbose = document.createElement("div");
  37. verbose.id = "verbose";
  38. document.getElementsByTagName("body")[0].appendChild(verbose);
  39. $("#verbose").css("background","#000");
  40. $("#verbose").css("opacity", "0.6");
  41. $("#verbose").css("color", "white");
  42. $("#verbose").css("position", "fixed");
  43. $("#verbose").css("top", "0");
  44. $("#verbose").css("pointer-events", "none");
  45. var x = $('.messageboard').length;
  46. $("#allMsg a em").text(x);
  47. var reader = '<button id="reader" onClick="autoread()"><a style="text-decoration: none; font-weight: normal;" href="#">Read All</a></button>';
  48. $(".unread_mess_bg").append(reader);
  49. var scriptinject = document.createElement("script");
  50. scriptinject.innerHTML = ["var i = 0;",
  51. "var x = $('.messageboard').length;",
  52. "function autoread(){",
  53. " document.getElementById('verbose').innerHTML += 'iEMB+: Running checks...<br />';",
  54. " document.getElementById('verbose').innerHTML += 'iEMB+: '+ x + ' messages remaining to read.<br />';",
  55. " $('#reader a').text('Reading all messages...');",
  56. " if (x=='0'){",
  57. " $('#reader a').text('All Messages are already Read!');",
  58. " setTimeout(function() { $('#reader a').text('Read All'); }, 2000);",
  59. " return;",
  60. " }",
  61. " var iframeread;",
  62. " iframeread = document.createElement('iframe');",
  63. " document.body.appendChild(iframeread);",
  64. " iframeread.height = '0';",
  65. " iframeread.src = $('a.messageboard')[i].href;",
  66. " x--;",
  67. " i++;",
  68. " checkread();",
  69. "}",
  70. "function checkread(){",
  71. " if (!x){",
  72. " document.getElementById('verbose').innerHTML += 'Done!<br />';",
  73. " $('#reader a').text('Done!');",
  74. " location.reload();",
  75. " }",
  76. "else if(x) {",
  77. " document.getElementById('verbose').innerHTML += 'iEMB+: Not done yet! rerunning...<br />';",
  78. " autoread();",
  79. " }",
  80. "}",
  81. " function setDP(){",
  82. " var dp = localStorage.getItem('profilePic');",
  83. " $('.iemb_user_left>img').attr('src', dp);",
  84. " $('.iemb_user_left>img').css('border-radius', '100%');",
  85. "}",
  86. " function changeDP(){",
  87. " var newdp = window.prompt('Enter URL of new image for your profile picture!');",
  88. " localStorage.setItem('profilePic', newdp);",
  89. " setDP();",
  90. "}",
  91.  
  92. ].join('\n');
  93. document.getElementsByTagName("head")[0].appendChild(scriptinject);
  94. var iframe = document.createElement("iframe");
  95. $('img[alt="Important"]').css("filter", "invert(0)");
  96. $('img[alt="Urgent"]').css("filter", "invert(0)");
  97. $('img[alt="Information"]').css("filter", "invert(0)");
  98. setDP();
  99. $('.iemb_user_left>img').click(function(){ changeDP();});
  100. $('.iemb_user_left>img').css("height", "40");
  101. $('.iemb_user_left>img').css("width", "40");
  102. $('.iemb_user_left>img').css("background-size", "cover");
  103. var toggleDark;
  104. if(localStorage.getItem("iEMBDark") == "0"){
  105. toggleDark = '<li style="text-align:center;"><a href="#" id="DarkToggle"><i class="fa fa-moon-o" aria-hidden="true"></i><br />Dark Mode</a></li>';
  106. }
  107. else if(localStorage.getItem("iEMBDark") == "1"){
  108. toggleDark = '<li style="text-align:center;"><a href="#" id="DarkToggle"><i class="fa fa-sun-o" aria-hidden="true"></i><br />Light Mode</a></li>';
  109. }
  110. $(toggleDark).insertBefore("#iemb_topnav .drop");
  111. console.log("iEMB+: Initialisation complete! All systems green!");
  112. $("#DarkToggle").click(function() {
  113. if($("#darkMode").length){
  114. $("#darkMode").remove();
  115. document.getElementById("DarkToggle").innerHTML = "<i class='fa fa-moon-o' aria-hidden='true'></i><br />Dark Mode";
  116. localStorage.setItem('iEMBDark', "0");
  117. return;
  118. }
  119. if(!$("#darkMode").length){
  120. document.getElementsByTagName("head")[0].appendChild(link);
  121. document.getElementById("DarkToggle").innerHTML = "<i class='fa fa-sun-o' aria-hidden='true'></i><br />Light Mode";
  122. localStorage.setItem('iEMBDark', "1");
  123. }
  124. });
  125. };