iEMB+

Makes the new iEMB more tolerable

目前为 2017-11-09 提交的版本,查看 最新版本

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