Greasy Fork 还支持 简体中文。

Highrise Enhancements

try to take over the world!

目前為 2016-12-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Highrise Enhancements
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  try to take over the world!
// @author       You
// @match        https://wodc.highrisehq.com/*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

var products = ['pt', 'puretane', 'bf', 'blueflame', 'blue flame', 'nuggy', 's5'];
var company = '';
var frame = document.createElement('iframe');
frame.style.cssText = 'z-index: -1; visibility: hidden; position: absolute; top: 0; left: 0;';

function settingsMenu() {
    var options = ['Auto share tasks', 'Highlight overdue tasks', 'Show full timestamp', 'Show last order in tasks'];
    var desc = ['Make sure checkbox "Let everyone see this task" is checked and hidden', 'Highlight overdue text next to tasks link', 'Show the time and date on notes', 'Grab last order date and show in the popup next to tasks'];

    var page_cover = document.createElement('div');
    document.body.appendChild(page_cover);
    page_cover.setAttribute('id', 'page_cover');
    page_cover.style.cssText = 'display: none; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 1000;';

    var settings_div = document.createElement('div');
    document.body.appendChild(settings_div);
    settings_div.setAttribute('id', 'settings_div');
    settings_div.style.cssText = 'width: 75%; left: 50%; margin-left: -17.5%; display: none; position: fixed; width: 600px; height: 300px; background: white; border-radius: 20px; text-align: center; z-index: 1001;';

    var ul = document.createElement('ul');
    settings_div.appendChild(ul);

    page_cover.addEventListener('click', function() {
        page_cover.style.display = 'none';
        settings_div.style.display = 'none';
    });

    for (var i = 0; i < options.length; i++) {
        var liButton = document.createElement('li');
        var liDesc = document.createElement('li');
        var button = document.createElement('button');
        button.innerHTML = options[i];
        ul.appendChild(liButton);
        ul.appendChild(liDesc);
        liButton.appendChild(button);
        liDesc.innerHTML = desc[i];
        liDesc.style.cssText = 'margin-bottom: 20px;';
        button.style.cssText = 'border: none !important; margin: 5px 0; border-radius: 5px; color: white;';

        var gm_var = options[i].replace(/ /g, '_');
        if (GM_getValue(gm_var) === undefined) {
            GM_setValue(gm_var, true);
        }

        if (GM_getValue(gm_var) === true) {
            button.style.backgroundColor = '#20a02a';
        }
        else {
            button.style.backgroundColor = '#cc3636';
        }

        button.addEventListener('click', function() {
            gm_var = this.innerHTML.replace(/ /g, '_');
            GM_setValue(gm_var, !GM_getValue(gm_var));

            if (GM_getValue(gm_var) === true) {
                this.style.backgroundColor = '#20a02a';
            }
            else {
                this.style.backgroundColor = '#cc3636';
            }
        });
		
		var update = document.createElement('a');
		update.innerHTML = 'Update';
		update.href = '';
    }
}

var orderLineDiv = document.createElement('div');

(function() {
    'use strict';
    
    var url = window.location.href;
    if (url.toLowerCase().indexOf('iframe') < 0) {
        window.load = start();
    }
})();

function start() {
    
    settingsMenu();
	document.body.appendChild(frame);
    
    if (GM_getValue('Highlight_overdue_tasks')) {
        highlightOverdue();
    }
    
    if (GM_getValue('Show_full_timestamp')) {
        var feed = document.getElementById('recordings');
        if (feed !== null) {
            fullTimestamp();
        }
    }
    
    if (GM_getValue('Show_last_order_in_tasks')) {
        var waitForPopup = setInterval(popupScanner, 200);
    }
    
    if (GM_getValue('Auto_share_tasks')) {
        taskcheckbox();
    }
    
    /*
    var hoursDiv = document.createElement('div');
    var button = document.createElement('button');
    document.body.insertBefore(hoursDiv, document.body.firstChild);
    hoursDiv.appendChild(button);
    button.innerHTML = 'test';
    hoursDiv.style.cssText = 'top: 200px; left: 200px;';*/
    
    settingsButton();
    
    //button.addEventListener('click', getHours);
}

function settingsButton() {
    var menu = document.getElementsByClassName('global_links')[0];
    var li = document.createElement('li');
    menu.appendChild(li);
    var button = document.createElement('button');
    li.appendChild(button);
    
    button.style.cssText = 'border: none; color: #56778b; font-size: 12px;';
    
    button.innerHTML = 'BONUS';
    button.addEventListener('mouseover', function() {
        button.style.color = 'black';
    });
    
    button.addEventListener('mouseout', function() {
        button.style.color = '#56778b';
    });
    
    button.addEventListener('click', settingsPopup);
}

function taskcheckbox() {
    var taskcheckbox = [];
    taskcheckbox.push(document.getElementById('public_checkbox_task_main'));
    if (document.getElementById('public_checkbox_task_page') !== null) {
        taskcheckbox.push(document.getElementById('public_checkbox_task_page'));
    }
    
    for (var i = 0; i < taskcheckbox.length; i++) {
        taskcheckbox[i].checked = 'checked';
        taskcheckbox[i].parentNode.style.display = 'none';

        var task = document.createElement('div');
        taskcheckbox[i].parentNode.parentNode.insertBefore(task, taskcheckbox[i].parentNode);

        if (taskcheckbox[i].checked) {
            task.innerHTML = '<i>Everyone can see this task</i>';
        }
        else {
            task.innerHTML = '<b>TASK HIDDEN</i>';
        }
        task.style.cssText = 'font-size: 15px !important;';
    }
}


function settingsPopup() {
    var page_cover = document.getElementById('page_cover');
    var settings_div = document.getElementById('settings_div');
    page_cover.style.display = 'block';
    settings_div.style.display = 'block';
}


function highlightOverdue() {
    var span = document.getElementsByTagName('span');
    var len = span.length;
    
    for (var i = 0; i < len; i++) {
        if (span[i].innerHTML.indexOf('overdue') > -1) {
            var num = span[i].innerHTML.split('overdue')[0];
            num = num.split(' ');
            num = num[num.length - 2];
            var text = num + ' ' + 'overdue';
            span[i].innerHTML = span[i].innerHTML.replace(text, '<div id="highlightoverdue">' + text + '</div>');
        }
    }
    
    var overdue = document.getElementById('highlightoverdue');
    overdue.style.cssText = 'color: red; display: inline-block; font-weight: bold;';
}

function fullTimestamp() {
    var timer = setInterval(function() {
        var feed = document.getElementById('recordings');
        var dates = feed.getElementsByClassName('date-container');
        var len = dates.length;
        var split, date, hour, min_sec, ampm;
        
        for (var i = 0; i < len; i++) {
            split = dates[i].getAttribute('data-timestamp').split(' ');
            hour = parseInt(split[1].split(':')[0]);
            min_sec = split[1].split(':');
            min_sec = min_sec[1] + ':' + min_sec[2];
            
            if (hour >= 8) {
                hour -= 8;
            }
            else {
                hour += 16;
            }

            if (hour > 12) {
                hour -= 12;
                ampm = 'PM';
            }
            else if (hour == 12) {
                ampm = 'PM';
            }
            else {
                ampm = 'AM';
            }
            
            if (hour < 10) {
                hour = '0' + hour.toString();
            }

            dates[i].style.cssText = 'color: #333; background: #f1f5f9; padding: 4px; border-radius: 8px; border: 1px solid #d7d7d7; text-align: center; display: block; width: 74px; height: 36px; float: right;';
            dates[i].innerHTML = split[0] + '<br>' + hour + ':' + min_sec + ' ' + ampm;
        }
    }, 50);
}

function loadFrame(link) {
    frame.src = link;
    frame.addEventListener('load', scrollToBottom);
}

function popupScanner() {
    var com = '';
    var popup = document.getElementById('quick_show_window');
    
    var inner;
    
    if (popup.style.display !== 'none') {
        var link = popup.getElementsByTagName('img')[0].parentNode.href;
        
        com = popup.getElementsByTagName('h1')[0].innerHTML;
        if (company !== com) {
            orderLineDiv.innerHTML = '<i>Loading orders...</i>';
            inner = popup.getElementsByClassName('quick_show_window_content')[0];
            inner.appendChild(orderLineDiv);
            company = com;
            loadFrame(link);
        }
    }
    else {
        company = '';
    }
}

function scrollToBottom() {
    var frameWindow = window.frames[0].document;

    var count = 0;
    var spinnerTimer = setInterval(function(){
        if (frameWindow.body.getElementsByClassName('spinner').length !== count) {
            count = frameWindow.body.getElementsByClassName('spinner').length;
            frame.contentWindow.scrollTo(0, frameWindow.body.scrollHeight);
        }
        else {
            clearInterval(spinnerTimer);
            scanFrame();
        }
    }, 800);
}

function scanFrame() {
    var framebody = frame.contentWindow.document.body;
    var contents = framebody.getElementsByClassName('recording-container');
    var len = contents.length;
    var type, cont, html, date;
    var searching = 1;
    var order = false;
    
    for (var i = 0; i < len; i++) {
        cont = contents[i].getElementsByClassName('text-content')[0];
        html = cont.innerHTML.toLowerCase();
        if (searching === 1) {
            date = fixDate(contents[i].getElementsByClassName('date-container')[0].getAttribute('data-timestamp'));
            if (html.indexOf('$') > -1) {
                searching = 0;
                for (var j = 0; j < products.length; j++) {
                    if (html.indexOf(products[j]) > -1) {
                        flag = true;
                    }
                }
                if (flag === true) {
                    type = 'Order';
                }
                else {
                    type = '???';
                }
            }
            else if (html.indexOf('sample') > -1) {
                searching = 0;
                type = 'Sample';
            }
        }
    }
    if (type === '') {
        type = 'null';
    }
    
    if (type !== 'null') {
        orderLineDiv.innerHTML = type + ' sent on ' + date;
    }
    else {
        orderLineDiv.innerHTML = 'No shipments found';
    }
}

function getHours() {
    var name = document.getElementsByClassName('name')[1].innerHTML.split(' |')[0];
    
    var addresses = document.getElementsByClassName('address data_group');
    var ind;
    var len = addresses.length;
    var label;
    for (var i = 0; i < len; i++) {
        label = addresses[i].getElementsByClassName('label');
        if (label[0].innerHTML.toLowerCase().indexOf('work') > -1) {
            ind = i;
        }
    }
    
    var splits;
    var blocks = [];
    var address = addresses[ind].getElementsByClassName('value')[0].innerHTML.replace(/<br>/g, '');
    var lines = address.split('\n');
    len = lines.length - 1;
    
    for (i = 0; i < len; i++) {
        splits = lines[i].split(' ');
        for (var j = 0; j < splits.length; j++) {
            blocks.push(splits[j]);
        }
    }
    
    var searchFrame = document.createElement('iframe');
    searchFrame.style.cssText = 'height: 1000px; width: 1000px;';
    document.body.insertBefore(searchFrame, document.body.firstChild);
    
    var url = 'https://www.google.com/';
    
    /*
    len = blocks.length;
    for (i = 0; i < len; i++) {
        if (blocks[i].length > 0) {
            url = url + blocks[i];
            if ((len - 1) !== i) {
                url = url + '+';
            }
        }
    }
    
    url = url.replace(/,/g, '');*/
    
    searchFrame.src = url;
}

function fixDate(date) {
    var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    var year = date.split('-')[0];
    var month = months[parseInt(date.split('-')[1]) - 1];
    var day = date.split('-')[2].substring(0, 2);
    
    return month + ' ' + day + ', ' + year;
}