WaterlooWorksNow

Waterloo Works script to add more features. Adds new tab functionality to listings and an expiring-soon indicator.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         WaterlooWorksNow
// @namespace    http://tampermonkey.net/
// @version      2.3
// @description  Waterloo Works script to add more features. Adds new tab functionality to listings and an expiring-soon indicator.
// @author       jyntran
// @match        https://waterlooworks.uwaterloo.ca/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var wwn = window.wwn = {};

    wwn.openTab = function(fn){
        var newTab = window.open(window.location.href);
        var fnBody = fn.toString().match(/function[^{]+\{([\s\S]*)\}$/)[1].trim();
        localStorage.setItem("wwnJobOpener", 'window.' + fnBody.toString());
        
        newTab.window.onload = function() {
            var loadingIconElem = document.createElement('span');
            var loadingElem = document.createElement('div');
            loadingIconElem.setAttribute('class', 'icon-cog icon-spin');
            loadingIconElem.setAttribute('style', 'font-size: 1000%; color: white;');
            loadingElem.setAttribute('id', 'wwnLoading');
            loadingElem.setAttribute('style', 'position: absolute; background: black; background: rgba(0,0,0,0.5); width: 100%; height: 100%; top: 0; left: 0; display: flex; align-items: center; justify-content: center; z-index: 1000;');
            loadingElem.appendChild(loadingIconElem);
            newTab.window.document.body.appendChild(loadingElem);
            
            newTab.window.eval(localStorage.wwnJobOpener);
        };
    };
    
    function renderExpiring() {
        $('.isAboutToExpire td:nth-child(' + 4 + ')').append(function() {
            var expiringElem = $('<span></span>');
            expiringElem.attr({
                'class': 'icon-exclamation-sign wwn-expiring',
                'style': 'color: #c00; margin: auto 4px',
                'title': 'Deadline today'
            });
            return expiringElem;
        });
    }
    
    function renderNewTabButtons() {
        // append button to listing
        $('.searchResult td:nth-child(' + 4 + ')').append(function(){
            var linkElem = $(this).find('a').get(0);
            var onclickContents = linkElem.onclick;
            var newTabSpanElem = $('<span></span>');
            newTabSpanElem.attr({
                'class': 'icon-external-link'
            });
            var newTabElem = $('<button></button>');
            newTabElem.attr({
                'class': 'btn btn-mini wwn-newtab',
                'style': 'margin: auto 4px',
                'title': 'Open in new tab',
                'onclick': 'wwn.openTab('+ onclickContents +');'
            });
            newTabElem.append(newTabSpanElem);
            return newTabElem;
        });
        
        // remove br element after job title link
        $('.searchResult td:nth-child(' + 4 + ') br').remove();
    }
    
    function renderWWN() {
        if (!$('.wwn-expiring').length) {
            renderExpiring();
        }
        if (!$('.wwn-newtab').length) {
            renderNewTabButtons();
        }
        
        $('#postingsTable').on('click', function() {
            setTimeout(renderWWN, 200);
        });
    }
    
    $(document).ready(renderWWN);
    

})();