Greasy Fork is available in English.

DSA Seasonal

Applies seasonal theme to DSA

Tính đến 15-08-2018. Xem phiên bản mới nhất.

// ==UserScript==
// @name         DSA Seasonal
// @locale       English (en)
// @namespace    COMDSPDSA
// @version      1.4
// @description  Applies seasonal theme to DSA
// @author       SD / Dan Overlander
// @include      http://sales.dell.com/*
// @include	     *olqa.preol.dell.com*
// @include	     *http://localhost:36865*
// @require      https://greasyfork.org/scripts/23115-tampermonkey-support-library/code/Tampermonkey%20Support%20Library.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.min.js
// @grant        none
// ==/UserScript==

// Since v01.30: Converted date format to ISO, to avoid future failure
// Since v01.20: Added Senior Citizens Day
// Since v01.10: Updated 4th July banner; it was being "checked" :)
// Since v01.00: Father's Day color tweak.  Added Independence Day. TWEAKED DATE CALCULATION!
// Since v0.961: Added Father's Day, Daylight Savings Time Ends, Halloween - thus completes about a 1-year cycle
// Since v0.96: Tweaked link colors of Tax Day
// Since v0.95: Added Tax/Theft Day
// Since v0.94: Annoying Easter header image swapped
// Since v0.93: Added St. Patrick's Day
// Since v0.92: TM library link changed. Tweak Spring Forward. Add option to invert; will need work later
// Since v0.91: Tweaked Spring Forward's colors
// Since v0.9: Tweaked President's Day colors
// Since v0.8: Disabled show-off theme control keyboard keys
// Since v0.7: Fixed MLK, added Presidents
// Since v0.6: Added Martin Luther King Day and Valentine's Day
// Since v0.5: Renamed. Tweaked Thanksgiving occurence. Added logging when no holiday is selected.
// Since v0.4: white opacity.8 background, different Easter image
// Since v0.3: Hacky keyboard toggling between 4 themes
// Since v0.2: Temporary full-web-accessible background images
// Since v0.1: gets next holiday and applies theme within X days of its date

(function() {
    'use strict';

    //var monthAbbr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    //var ordinals = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth', 'Thirteenth', 'Fourteenth', 'Fifteenth', 'Sixteenth', 'Seventeenth', 'Eighteenth', 'Nineteenth', 'Twentieth', 'Twenty-First', 'Twenty-Second', 'Twenty-Third', 'Twenty-Fourth', 'Twenty-Fifth', 'Twenty-Sixth', 'Twenty-Seventh', 'Twenty-Eighth', 'Twenty-Ninth', 'Thirtieth', 'Thirty-First'];

    var areKeysAdded = areKeysAdded || false,
        holidays = { // keys are formatted as month,week,day, zero-based
            "0,2,1": "Martin Luther King Day",
            "1,2,3": "Valentine's Day",
            "1,3,1": "President's Day",
            "2,2,0": "Spring Forward",
            "2,2,6": "St. Patrick's Day",
            "3,1,0": "Easter", // approximate
            "3,2,2": "Tax Day",
            "4,2,0": "Mother's Day",
            "4,-1,1": "Memorial Day",
            "5,2,0": "Father's Day",
            "6,0,3": "Independence Day",
            "7,3,2": "Senior Citizens Day",
            "8,0,1": "Labor Day",
            "9,5,6": "Halloween", // untested, approximate
            "10,1,0": "Daylight Savings Time Ends",
            "10,4,4": "Thanksgiving",
            "11,4,2": "Christmas" // approximate
        };
    function isoFormat(year, month, date) {
        if (year == null || month == null || date == null) {
            return null;
        }

        var mill;
        year = year.toString();
        month = month.toString();
        date = date.toString();
        if (year.length === 2) {
            mill = new Date().getFullYear().toString().substr(0,2);
            year = mill + year;
        }
        month = ('0' + month);
        month = month.substr(month.length-2, 2);

        date = ('0' + date);
        date = date.substr(date.length-2, 2);
        return year + '-' + month + '-' + date;
    }
    function getHoliday(month, week, day) {
        return holidays[month + "," + week + "," + day];
    }
    function getNextHoliday() {
        var myYear = moment().year(),
            oneYearFromNow = moment().year() + 1,
            myMonth = moment().month(),
            myWeek,
            myDate = moment().date()-1,
            myDayOfWeek,
            startDate = moment(isoFormat(myYear, myMonth+1, myDate+1)),
            scanDate = startDate,
            daysInMonth = (moment(scanDate).endOf('month').date())-1,
            holiday;

        while (holiday === undefined && myDate < 33 && myYear < oneYearFromNow) {
            scanDate = moment(isoFormat(myYear, myMonth+1, myDate+1));
            myWeek = Math.ceil(moment(scanDate).date() / 7)-1;
            myDayOfWeek = moment(scanDate).day();
            holiday = getHoliday(myMonth, myWeek, myDayOfWeek);
            //tm.log(daysInMonth + ', ' + myMonth + ' '  + myWeek + ' ' + myDayOfWeek + ' = ' + scanDate + ' (found holiday: ' + holiday + ')');

            myDate++;
            if (myDate > daysInMonth) {
                myDate = 0;
                myMonth++;
                if (myMonth > 11) {
                    myMonth = 0;
                    myYear++;
                }
                daysInMonth = (moment(scanDate).endOf('month').date())-1;
            }
        }

        var holidayObj = {
            name: holiday,
            diff: -(moment(startDate).diff(scanDate, 'days'))
        };

        return holidayObj;
    }

    function applyHoliday(holidayName) {
        switch (holidayName) {
            case 'Martin Luther King Day' :
                pageImage = 'http://www.dorkforce.com/bkg/martin_luther_king.jpg';
                headerImage = 'http://dorkforce.com/bkg/martin_luther_king_header.png';
                buttonColor = 'CadetBlue';
                backgroundColor = 'cornsilk';
                break;
            case "Valentine's Day" :
                pageImage = 'http://www.psdgraphics.com/file/valentines-day.jpg';
                headerImage = 'http://www.hdwallpapersfreedownload.com/uploads/large/love/valentines-day-theme-background-wallpaper-hd.jpg';
                buttonColor = 'HotPink';
                backgroundColor = 'LightPink';
                break;
            case "President's Day" :
                pageImage = 'http://votemadera.com/wp-content/uploads/2015/07/random-wallpapers-american-flag-wallpaper-343171.png';
                headerImage = 'https://i.ytimg.com/vi/QnGUN52v2O8/maxresdefault.jpg';
                buttonColor = '#005CB7';
                buttonTextColor = '#ccdef0';
                dropdownColor = '#7faddb';
                backgroundColor = 'LightSkyBlue';
                break;
            case 'Christmas' :
                pageImage = 'https://ak3.picdn.net/shutterstock/videos/11518193/thumb/1.jpg';
                headerImage = 'https://happyholidaysblog.com/wp-content/uploads/Christmas-Background-17.jpg';
                buttonColor = 'blue';
                backgroundColor = 'silver';
                break;
            case 'Thanksgiving' :
                pageImage = 'https://img.clipartxtras.com/4783b16edc739f156c59a6a284c1f1b6_thanksgiving-clipart-backgrounds-for-free-happy-thanksgiving-free-thanksgiving-background-clipart_600-315.jpeg';
                headerImage = 'http://ak5.picdn.net/shutterstock/videos/12619445/thumb/1.jpg';
                buttonColor = 'orange';
                backgroundColor = 'lightgoldenrodyellow';
                break;
            case 'Spring Forward' :
                pageImage = 'http://rcommoncdn.entrata.com/website_templates/leaves_2/images/backgrounds/spring_leaves.jpg';
                headerImage = 'https://tashamillergriffith.files.wordpress.com/2014/04/wildflowers-texas-spring-2014-2.jpg';
                buttonColor = 'Aqua';
                backgroundColor = 'Aquamarine';
                //invertedColor = true;
                dropShadowText = true;
                break;
            case "St. Patrick's Day" :
                pageImage = 'http://www.capify.com/wp-content/uploads/2016/02/St.-Patricks-Day1.jpg';
                headerImage = 'https://az616578.vo.msecnd.net/files/2017/03/11/636248708426397913-1721321493_mac_wallpaper_16x9.jpg';
                buttonColor = '#144314';
                backgroundColor = '#062C06';
                //dropdownColor = '#7faddb';
                break;
            case 'Easter' :
                pageImage = 'https://i.pinimg.com/originals/e5/7b/9b/e57b9bc0f14b0ff3d8ba2833a6f8603f.jpg';
                headerImage = 'https://www.freewebheaders.com/wordpress/wp-content/uploads/pink-purple-sky-and-spring-nature-landscape-header.jpg';
                buttonColor = 'DeepPink';
                backgroundColor = '#c0fff4';
                break;
            case 'Tax Day' :
                pageImage = 'https://www.wthr.com/sites/wthr.com/files/field/image/Tax-Returns-1040-generic-970px.jpg';
                headerImage = 'https://i1.wp.com/patrioticmillionaires.org/wp-content/uploads/lets-talk-tax-day-2017.jpg';
                backgroundColor = 'darkolivegreen';
                dropdownColor = 'aliceblue';
                break;
            case "Father's Day" :
                pageImage = 'https://www.preachit.org/images/ppt_thumbs/1763-slide2-600.jpg';
                headerImage = 'http://images.all-free-download.com/images/graphicthumb/father_day_background_hanging_objects_decoration_colored_icons_6828759.jpg';
                buttonColor = '#012255';
                backgroundColor = '#9FD7E4';
                dropdownTitle = 'white';
                dropdownColor = '#7faddb';
                break;
            case "Independence Day" :
                pageImage = 'https://am14.akamaized.net/med/cnt/uploads/2013/07/fw.jpg';
                headerImage = 'http://us.blog.swagbucks.com/wp-content/uploads/2016/06/PRT-3276-900x300-blog.png';
                backgroundColor = 'darkblue';
                dropdownColor = 'aliceblue';
                appTitleColor = 'white';
                break;
            case "Senior Citizens Day" :
                pageImage = 'https://d2v9y0dukr6mq2.cloudfront.net/video/thumbnail/H9EbKgwIiq72f2cq/videoblocks-senior-citizen-immersed-in-virtual-reality-with-help-of-special-vr-glasses-and-stands-on-background-of-bright-wall-in-cafe-during-day_rakyd0mnl_thumbnail-full01.png';
                headerImage = 'https://www.vip-polymers.com/wp-content/uploads/2015/04/Global-Banner.jpg';
                buttonColor = '#012255';
                // buttonTextColor
                backgroundColor = '#B28EC7';
                dropdownTitle = 'white';
                dropdownColor = '#C09DC7';
                // invertedColor
                // dropShadowText
                appTitleColor = 'white';
                break;
            case "Labor Day" :
                pageImage = 'https://www.phillymag.com/wp-content/uploads/sites/3/2015/09/Labor-Day-Sales.jpg';
                headerImage = 'http://www.capitolsocial.com/wp-content/uploads/2016/04/Background-RWB-Stage.jpg';
                buttonColor = '#012255';
                // buttonTextColor
                backgroundColor = '#9FD7E4';
                dropdownTitle = 'white';
                dropdownColor = '#7faddb';
                // invertedColor
                // dropShadowText
                // appTitleColor
                break;
            case "Halloween" :
                pageImage = 'http://hdbackgroundspic.com/wp-content/uploads/2016/09/beautiful-wallpaper-for-desktop.jpg';
                headerImage = 'https://pre00.deviantart.net/49cc/th/pre/f/2012/086/8/2/82481e256abf5175ae120bc4370ca60a-d4u4dsq.jpg';
                buttonColor = 'black';
                backgroundColor = '#9FD7E4';
                dropdownTitle = 'white';
                dropdownColor = '#FFC898';
                break;
            case "Daylight Savings Time Ends" :
                pageImage = 'https://www.babysleepsite.com/wp-content/uploads/2015/09/bigstock-Autumn-Leaves-Background-103865501.jpg';
                headerImage = 'https://ak0.picdn.net/shutterstock/videos/5219960/thumb/1.jpg';
                buttonColor = '#4D1E00';
                backgroundColor = '#FF7619';
                dropdownTitle = 'white';
                //dropdownColor = '#FFC898';
                break;
            default:
                break;
        }
        tm.addGlobalStyle('body { background: url("' + pageImage + '") no-repeat center center fixed; background-size: cover; }');
        tm.addGlobalStyle('.main-nav { background-image: url("' + headerImage + '"); background-size: cover; }');
        tm.addGlobalStyle('.main-nav, .btn-primary, button { background-color: ' + buttonColor + ' !important;}');
        tm.addGlobalStyle('#dropMenu button { background-color:inherit !important; color: ' + buttonColor + '; }');
        tm.addGlobalStyle('.view-nav { background-color: ' + backgroundColor + ' !important; }');
        tm.addGlobalStyle('.content-view {background-color: inherit;}');
        tm.addGlobalStyle('.content-area {background-color: rgba(255, 255, 255, 0.8);}');
        tm.addGlobalStyle('a { color: ' + buttonColor + ';}');
        if (buttonTextColor != null) tm.addGlobalStyle('.btn-primary, button { color: ' + buttonTextColor + ' !important;}');
        if (dropdownTitle != null) tm.addGlobalStyle('#menu_versionToggle, .current-business-unit a { color: ' + dropdownTitle + ' !important;}');
        if (dropdownColor != null) tm.addGlobalStyle('.dropdown-menu { background-color: ' + dropdownColor + ' !important;}');
        if (invertedColor === true) tm.addGlobalStyle('a { -webkit-filter: invert(100%); filter: invert(100%); }');
        if (dropShadowText === true) tm.addGlobalStyle('a { text-shadow: 1px 1px 1px #000; }');
        if (appTitleColor != null) tm.addGlobalStyle('#welcomeMessage, .customer-header .segment-info, .customer-header h5, customer-details-navigation .row, customer-details-navigation .segment-info { color: ' + appTitleColor + '; }');
    }

    var nextHoliday = getNextHoliday(),
        pageImage,
        headerImage,
        buttonColor,
        buttonTextColor,
        dropdownColor,
        dropdownTitle,
        invertedColor,
        dropShadowText,
        appTitleColor,
        backgroundColor;
    if (nextHoliday.diff < 19) {
        tm.log('Showing ' + nextHoliday.name);
        applyHoliday(nextHoliday.name);
    } else {
        tm.log(nextHoliday.name + ' is ' + nextHoliday.diff + ' days away.');
    }

    areKeysAdded = true;
    if (!areKeysAdded) {
        areKeysAdded = true;

        $(document).unbind('keyup');

        $(document).keyup(function(e) {
            if (e.keyCode == 37 && e.ctrlKey) { applyHoliday('Christmas'); } // Ctrl-Left
            if (e.keyCode == 39 && e.ctrlKey) { applyHoliday('Easter'); } // Ctrl-Right
            if (e.keyCode == 38 && e.ctrlKey) { applyHoliday('Thanksgiving'); } // Ctrl-Up
            if (e.keyCode == 40 && e.ctrlKey) { applyHoliday('Spring Forward'); } // Ctrl-Down
        });
        // these SHOULD initialize the dropdown menus, but no longer do:
        $('.dropdown[title="Group by"] a').trigger('click').next().css('display', 'none');
        $('.dropdown[title="Person"] a').trigger('click').next().css('display', 'none');
    }
})();