WME Notes

Simple space to keep notes

Verze ze dne 26. 08. 2023. Zobrazit nejnovější verzi.

// ==UserScript==
// @name           WME Notes
// @description    Simple space to keep notes
// @namespace      https://www.waze.com/user/editor/Craig24x7
// @version        0.1
// @match          https://waze.com/editor*
// @match          https://waze.com/*/editor*
// @match          https://beta.waze.com/editor*
// @match          https://beta.waze.com/*/editor*
// @include        /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
// @author         Craig24x7
// @grant          GM_setValue
// @grant          GM_getValue
// @license        MIT
// ==/UserScript==

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

(function() {

    'use strict';
    const debug = false;

    var autoRefreshDelay = 60000; // ms - 1 minute
    var userList;

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

    function initWMENotes() {
        console.log('WME Notes: Loaded');
        const { tabLabel, tabPane } = W.userscripts.registerSidebarTab("wme-chat-online-users");
        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); }
    }

    $(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;
        console.log('Next note is ' + nextNote + ' - this one is ' + currentNote);

        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;
        console.log('Previous note is ' + prevNote + ' - this one is ' + currentNote);

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

})();