WME Notes

Simple space to keep notes

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
    });

})();