_profile

onlinesequencer more buttons!

Feb 23rd, 2025 (edited)
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Onlinesequencer extra buttons
  3. // @namespace   eepic
  4. // @match        *://onlinesequencer.net/*
  5. // @match        *://test.onlinesequencer.net/*
  6. // @grant       none
  7. // @version     1.0
  8. // @author      eepic
  9. // @description Adds buttons for: SetDetune, SetGrid, SetTimeSig, Solo Lock, Lock All, Unlock All
  10. // @icon https://onlinesequencer.net/favicon.ico
  11. // @run-at       document-end
  12. // ==/UserScript==
  13.  
  14. (function () {
  15.     'use strict';
  16.  
  17.     if (!document.querySelector("#sequencer_main_row")) {
  18.         console.log("sequencer not found");
  19.         return;
  20.     }
  21.  
  22.     // helper functions
  23.     function lock(id, locked) {
  24.       instMgr.setLocked(id, locked)
  25.       setSimpleInstrumentSettingsLockState(id, locked)
  26.     }
  27.     function repaint() {
  28.       fillAdvancedInstrumentSettings()
  29.       fillSimpleInstrumentSettings()
  30.       SequencerView.repaint(kRepaintNotesChanged)
  31.     }
  32.  
  33.     function useFunction(promptMsg, useThisFunction) {
  34.       let userInput = prompt(promptMsg);
  35.       if (userInput === null) {
  36.           return; // user cancelled?
  37.       } else if (userInput !== null && /^[0-9+\-*/().\s]+$/.test(userInput)) {
  38.           let number = parseFloat(eval(userInput));
  39.           if (!isNaN(number)) {
  40.               if (useThisFunction == setDetune) {
  41.                   useThisFunction(instrument, number);
  42.               } else {
  43.                   useThisFunction(number);
  44.               }
  45.           } else {
  46.               alert("Not a number!");
  47.           }
  48.       } else {
  49.         alert("Invalid input!");
  50.       }
  51.     }
  52.  
  53.     const observe = new MutationObserver(() => {
  54.         let dropDown = document.querySelector("#tools-menu > ul:nth-child(2)");
  55.         if (dropDown) {
  56.             observe.disconnect();
  57.  
  58.             function newButton(textContent, onClick) {
  59.               let button = document.createElement("li");
  60.               button.setAttribute("tabindex", "-1");
  61.               button.textContent = textContent;
  62.               button.addEventListener("click", onClick)
  63.               dropDown.appendChild(button);
  64.             }
  65.  
  66.             function divButton(textContent, onClick, inner) {
  67.               let div = document.createElement('div');
  68.               div.textContent = textContent;
  69.               div.className = 'inner-option';
  70.               div.addEventListener('click', e => {
  71.                 e.stopPropagation();
  72.                 onClick();
  73.               })
  74.               inner.append(div)
  75.             }
  76.  
  77.             const li1 = document.createElement('li');
  78.             li1.className = 'inner-parent';
  79.             li1.tabIndex = 0;
  80.  
  81.             const inner1 = document.createElement('div');
  82.             inner1.className = 'multi-buttons';
  83.  
  84.             divButton("Solo Lock", function() {
  85.               instMgr.forEach((id) => {
  86.                 if (id == instrument) {
  87.                   lock(id, false)
  88.                 } else {
  89.                   lock(id, true)
  90.                 }
  91.               });
  92.               repaint();
  93.             }, inner1);
  94.  
  95.             divButton("Lock All", function() {
  96.               instMgr.forEach((id) => {
  97.                 lock(id, true)
  98.               });
  99.               repaint();
  100.             }, inner1);
  101.  
  102.             divButton("Unlock All", function() {
  103.               instMgr.forEach((id) => {
  104.                 lock(id, false)
  105.               });
  106.               repaint();
  107.             }, inner1);
  108.  
  109.             li1.append(inner1);
  110.             dropDown.append(li1);
  111.  
  112.             // more buttons
  113.             newButton("Set time sig", () => useFunction("Please enter a number (4 = 4/4, 5 = 5/4, etc)", setTimeSig));
  114.             newButton("Set grid size", () => useFunction("Please enter a number (divisions of one note, example: setGrid(1) -> 1/4, setGrid(4) -> 1/16)", setGrid));
  115.             newButton("Set instrument detune", () => useFunction("Please enter a number (in cents) to detune the current instrument:", setDetune));
  116.         }
  117.     });
  118.  
  119.     const style = document.createElement('style');
  120.     style.textContent = `
  121.     .inner-parent:hover {
  122.       background: none !important;
  123.       color: inherit !important;
  124.     }
  125.  
  126.     .multi-buttons {
  127.       display: flex;
  128.       cursor: default;
  129.     }
  130.  
  131.     .inner-option {
  132.       flex: 1;
  133.       text-align: center;
  134.       cursor: pointer;
  135.       background: transparent;
  136.     }
  137.  
  138.     .inner-option:hover {
  139.       background: #d38b0d;
  140.       color: white;
  141.     }
  142.  
  143.     .os-dropdown-menu {
  144.       width: 160px !important;
  145.     }
  146.     `;
  147.     document.head.appendChild(style);
  148.  
  149.     observe.observe(document.body, { childList: true, subtree: true });
  150. })();
  151.  
Advertisement
Add Comment
Please, Sign In to add comment