Highrise Enhancements

try to take over the world!

2016/12/29のページです。最新版はこちら

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Highrise Enhancements
// @namespace    http://tampermonkey.net/
// @version      0.3
// @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;';

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 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 = 'padding: 50px; width: 600px; left: 50%; margin-left: -17.5%; display: none; position: fixed; 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 = '#116D5F';
        }
        else {
            button.style.backgroundColor = '#bd4b4b';
        }

        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 = '#116D5F';
            }
            else {
                this.style.backgroundColor = '#bd4b4b';
            }
        });
    }
	
	var update = document.createElement('a');
	update.innerHTML = 'Update';
	update.href = 'https://greasyfork.org/scripts/26136-highrise-enhancements/code/Highrise%20Enhancements.user.js';
	update.style.cssText = 'display: block; margin-top: 50px; font-size: 2em; font-weight: bold; text-decoration: none; color: #13715C;';
	settings_div.appendChild(update);
}

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;
}