iEMB+

Makes the new iEMB more tolerable

Versione datata 09/11/2017. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         iEMB+
// @namespace    http://yeoxingyee.ml/
// @version      1.0.3
// @description  Makes the new iEMB more tolerable
// @author       YXY
// @match        *://iemb.hci.edu.sg/Board/BoardList*
// @match        *://iemb.hci.edu.sg/Board/Detail*
// @match        *://iemb.hci.edu.sg/Board/content*
// @grant        none
// ==/UserScript==
window.onload=function(){
    var link = document.createElement("link");
    link.href = "https://dl.dropboxusercontent.com/s/yed55pppaod34jd/iemb%2B.css";
    link.type = "text/css";
    link.rel = "stylesheet";
    link.id = "darkMode";
    var script = document.createElement("script");
    script.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js";
    if(localStorage.getItem("iEMBDark") == "1") document.getElementsByTagName("head")[0].appendChild(link);
    document.getElementsByTagName("head")[0].appendChild(script);
    var firstTime = localStorage.getItem("iEMBFirst");
    if(!firstTime){
        window.alert("Welcome to iEMB+!\nThis is a mini tutorial on how to use this script!\n(Click OK to continue)");
        window.alert("Firstly, the read all button will read everything! (Refresh after the reload to make sure everything's read) \nTip: 1/3");
        window.alert("Next, you can toggle dark/light mode by clicking the button in the top menu! \nTip: 2/3");
        window.alert("Lastly, change your profile picture by clicking on it! \nTip: 3/3");
        window.alert("And... that's it! If you have any questions / feedback contact me at \"[email protected]\" with the subject heading of \"iEMB+ Feedback!\"\nEnjoy!");
        localStorage.setItem("iEMBFirst", "1");
    }
    var dp = localStorage.getItem("profilePic");
    if(!dp){
        dp = window.prompt("Profile pic not set! \n Please enter a direct link to the image that you want for your profile picture!");
        $('.iemb_user_left>img').attr('src', dp);
        localStorage.setItem("profilePic", dp);
    }
    console.log("iEMB+: Initialising...");
    var verbose = document.createElement("div");
    verbose.id = "verbose";
    document.getElementsByTagName("body")[0].appendChild(verbose);
    $("#verbose").css("background","#000");
    $("#verbose").css("opacity", "0.6");
    $("#verbose").css("color", "white");
    $("#verbose").css("position", "fixed");
    $("#verbose").css("top", "0");
    $("#verbose").css("pointer-events", "none");
    var x = $('.messageboard').length;
    $("#allMsg a em").text(x);
    var reader = '<button id="reader" onClick="autoread()"><a style="text-decoration: none; font-weight: normal;" href="#">Read All</a></button>';
    $(".unread_mess_bg").append(reader);
    var scriptinject = document.createElement("script");
    scriptinject.innerHTML = ["var i = 0;",
                              "var x = $('.messageboard').length;",
                              "function autoread(){",
                              "  document.getElementById('verbose').innerHTML += 'iEMB+: Running checks...<br />';",
                              "  document.getElementById('verbose').innerHTML += 'iEMB+: '+ x + ' messages remaining to read.<br />';",
                              "  $('#reader a').text('Reading all messages...');",
                              "  if (x=='0'){",
                              "    $('#reader a').text('All Messages are already Read!');",
                              "    setTimeout(function() { $('#reader a').text('Read All'); }, 2000);",
                              "    return;",
                              "  }",
                              "  var iframeread;",
                              "    iframeread = document.createElement('iframe');",
                              "    document.body.appendChild(iframeread);",
                              "    iframeread.height = '0';",
                              "    iframeread.src = $('a.messageboard')[i].href;",
                              "    x--;",
                              "    i++;",
                              "  checkread();",
                              "}",
                              "function checkread(){",
                              "  if (!x){",
                              "    document.getElementById('verbose').innerHTML += 'Done!<br />';",
                              "    $('#reader a').text('Done!');",
                              "    location.reload();",
                              "  }",
                              "else if(x) {",
                              "    document.getElementById('verbose').innerHTML += 'iEMB+: Not done yet! rerunning...<br />';",
                              "    autoread();",
                              "  }",
                              "}",
                              "    function setDP(){",
                              "    var dp = localStorage.getItem('profilePic');",
                              "    $('.iemb_user_left>img').attr('src', dp);",
                              "    $('.iemb_user_left>img').css('border-radius', '100%');",
                              "}",
                              "    function changeDP(){",
                              "    var newdp = window.prompt('Enter URL of new image for your profile picture!');",
                              "    if(newdp){localStorage.setItem('profilePic', newdp);",
                              "    setDP();}",
                              "}",

                             ].join('\n');
    document.getElementsByTagName("head")[0].appendChild(scriptinject);
    var iframe = document.createElement("iframe");
    $('img[alt="Important"]').css("filter", "invert(0)");
    $('img[alt="Urgent"]').css("filter", "invert(0)");
    $('img[alt="Information"]').css("filter", "invert(0)");
    setDP();
    $('.iemb_user_left>img').click(function(){ changeDP();});
    $('.iemb_user_left>img').css("height", "40");
    $('.iemb_user_left>img').css("width", "40");
    $('.iemb_user_left>img').css("background-size", "cover");
    var toggleDark;
    if(localStorage.getItem("iEMBDark") == "0" || !localStorage.getItem("iEMBDark")){
        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>';
    }
    else if(localStorage.getItem("iEMBDark") == "1"){
        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>';
    }
    $(toggleDark).insertBefore("#iemb_topnav .drop");
    console.log("iEMB+: Initialisation complete! All systems green!");
    $("#DarkToggle").click(function() {
        if($("#darkMode").length){
            $("#darkMode").remove();
            document.getElementById("DarkToggle").innerHTML = "<i class='fa fa-moon-o' aria-hidden='true'></i><br />Dark Mode";
            localStorage.setItem('iEMBDark', "0");
            return;
        }
        if(!$("#darkMode").length){
            document.getElementsByTagName("head")[0].appendChild(link);
            document.getElementById("DarkToggle").innerHTML = "<i class='fa fa-sun-o' aria-hidden='true'></i><br />Light Mode";
            localStorage.setItem('iEMBDark', "1");
        }
    });
    $(".iemb_sidebar").css("height", "auto");
    $(".iemb_sidebar").css("min-height", "100%");
};