WME Notes

Simple space to keep notes

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name           WME Notes
// @description    Simple space to keep notes
// @namespace      https://www.waze.com/user/editor/Craig24x7
// @version        0.3
// @match           *://*.waze.com/*editor*
// @exclude         *://*.waze.com/user/editor*
// @author         Craig24x7
// @grant          GM_setValue
// @grant          GM_getValue
// @license        MIT
// ==/UserScript==

/* global W */
/* global I18n */
/* global $ */

(function() {

    'use strict';
    const debug = false;

    document.addEventListener("wme-ready", initWMENotes, { once: true });

    function initWMENotes() {
        const { tabLabel, tabPane } = W.userscripts.registerSidebarTab("wme-note");
        var lastPage = GM_getValue("wmenotesLastPage");
        if (isNaN(lastPage)) { lastPage = 1; }
        var lastNoteValue = GM_getValue("wmenotes" + GM_getValue("wmenotesLastPage"));
        if (lastNoteValue == undefined) { lastNoteValue = ""; }
        tabLabel.innerText = '📑';
        tabLabel.title = 'WME Notes';
        tabPane.id = 'sidepanel-wme-notes';
        tabPane.innerHTML = "<h2>WME Notes";
        tabPane.innerHTML += '<input type="button" style="width:40%; font-size:1.5em; height:25px; transform:scale(-1,1);" value="&#x27A6;" id="wme-notes-prev" /><div id="wme-notes-current" style="max-width:10%; font-size:1.2em; height:25px; width:10%; overflow:hidden; display:inline-block; text-align:center; vertical-align:middle; font-weight:bold;">'+lastPage+'</div><input type="button" style="width:40%; height:25px; font-size:1.5em;" value="&#x27A6;" id="wme-notes-next" />';
        tabPane.innerHTML += '<textarea id="wme-notes" style="width:90%; height:640px; font-size:12px; padding:10px;">' + lastNoteValue + '</textarea>';
        if (lastPage < 2) { $('#wme-notes-prev').prop('disabled', true); }
        if (lastPage > 9) { $('#wme-notes-next').prop('disabled', true); }
        console.log('WME Notes: Loaded');
    }

    $(document).on('keyup', '#wme-notes', function() {
        var currentNote = parseInt($('#wme-notes-current').text(),10);
        GM_setValue('wmenotes'+currentNote, $('#wme-notes').val());
    });

    $(document).on('click', '#wme-notes-next', function() {
        var currentNote = parseInt($('#wme-notes-current').text(),10);
        var nextNote = currentNote+1;
        if (nextNote > 10) { return; }
        if (nextNote == 10) { $('#wme-notes-next').prop('disabled', true); }
        if (nextNote < 10) { $('#wme-notes-prev').prop('disabled', false); }
        $('#wme-notes-current').text(nextNote);
        $('#wme-notes').val(GM_getValue('wmenotes'+nextNote));
        GM_setValue('wmenotesLastPage', nextNote);
    });

    $(document).on('click', '#wme-notes-prev', function() {
        var currentNote = parseInt($('#wme-notes-current').text(),10);
        var prevNote = currentNote-1;
        if (prevNote < 1) { return; }
        if (prevNote == 1) { $('#wme-notes-prev').prop('disabled', true); }
        if (prevNote > 1) { $('#wme-notes-next').prop('disabled', false); }
        $('#wme-notes-current').text(prevNote);
        $('#wme-notes').val(GM_getValue('wmenotes'+prevNote));
        GM_setValue('wmenotesLastPage', prevNote);
    });

})();