added cut,copy,paste,select all context menu for inputs

This commit is contained in:
booploops 2022-06-02 22:19:09 -07:00
parent 3d168cd359
commit 9185f75110
2 changed files with 284 additions and 233 deletions

View file

@ -212,6 +212,9 @@
"podcast.episodes": "Episodes", "podcast.episodes": "Episodes",
"podcast.playEpisode": "Play Episode", "podcast.playEpisode": "Play Episode",
"podcast.website": "Podcast Website", "podcast.website": "Podcast Website",
"action.cut": "Cut",
"action.paste": "Paste",
"action.selectAll": "Select All",
"action.edit": "Edit", "action.edit": "Edit",
"action.done": "Done", "action.done": "Done",
"action.editTracklist": "Edit Tracklist", "action.editTracklist": "Edit Tracklist",

View file

@ -2,32 +2,31 @@ var notyf = new Notyf();
const MusicKitObjects = { const MusicKitObjects = {
LibraryPlaylist: function () { LibraryPlaylist: function () {
this.id = "" this.id = "";
this.type = "library-playlist-folders" this.type = "library-playlist-folders";
this.href = "" this.href = "";
this.attributes = { this.attributes = {
dateAdded: "", dateAdded: "",
name: "" name: "",
} };
this.playlists = [] this.playlists = [];
} },
} };
// limit an array to a certain number of items // limit an array to a certain number of items
Array.prototype.limit = function (n) { Array.prototype.limit = function (n) {
return this.slice(0, n); return this.slice(0, n);
}; };
Vue.component('animated-number', { Vue.component("animated-number", {
template: "<div style='display: inline-block;'>{{ displayNumber }}</div>", template: "<div style='display: inline-block;'>{{ displayNumber }}</div>",
props: { 'number': { default: 0 } }, props: { number: { default: 0 } },
data() { data() {
return { return {
displayNumber: 0, displayNumber: 0,
interval: false interval: false,
} };
}, },
ready() { ready() {
@ -49,110 +48,110 @@ Vue.component('animated-number', {
this.displayNumber = this.displayNumber + change; this.displayNumber = this.displayNumber + change;
} }
}, 20); }, 20);
} },
} },
}) });
Vue.component('sidebar-library-item', { Vue.component("sidebar-library-item", {
template: '#sidebar-library-item', template: "#sidebar-library-item",
props: { props: {
name: { name: {
type: String, type: String,
required: true required: true,
}, },
page: { page: {
type: String, type: String,
required: true required: true,
}, },
svgIcon: { svgIcon: {
type: String, type: String,
required: false, required: false,
default: '' default: "",
}, },
cdClick: { cdClick: {
type: Function, type: Function,
required: false required: false,
} },
}, },
data: function () { data: function () {
return { return {
app: app, app: app,
svgIconData: "" svgIconData: "",
} };
}, },
async mounted() { async mounted() {
if (this.svgIcon) { if (this.svgIcon) {
this.svgIconData = await this.app.getSvgIcon(this.svgIcon) this.svgIconData = await this.app.getSvgIcon(this.svgIcon);
} }
}, },
methods: {} methods: {},
}); });
function fallbackinitMusicKit() { function fallbackinitMusicKit() {
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
function loadAlternateKey() { function loadAlternateKey() {
let parsedJson = JSON.parse(this.responseText) let parsedJson = JSON.parse(this.responseText);
MusicKit.configure({ MusicKit.configure({
developerToken: parsedJson.developerToken, developerToken: parsedJson.developerToken,
app: { app: {
name: 'Apple Music', name: "Apple Music",
build: '1978.4.1', build: "1978.4.1",
version: "1.0" version: "1.0",
}, },
sourceType: 24, sourceType: 24,
suppressErrorDialog: true suppressErrorDialog: true,
}) });
setTimeout(() => { setTimeout(() => {
app.init() app.init();
if (app.cfg.visual.window_background_style == "mica" && !app.isDev) { if (app.cfg.visual.window_background_style == "mica" && !app.isDev) {
app.spawnMica() app.spawnMica();
} }
}, 1000) }, 1000);
} }
request.addEventListener("load", loadAlternateKey); request.addEventListener("load", loadAlternateKey);
request.open("GET", "https://raw.githubusercontent.com/lujjjh/LitoMusic/main/token.json"); request.open(
"GET",
"https://raw.githubusercontent.com/lujjjh/LitoMusic/main/token.json"
);
request.send(); request.send();
} }
document.addEventListener('musickitloaded', function () { document.addEventListener("musickitloaded", function () {
console.log('MusicKit loaded') console.log("MusicKit loaded");
// MusicKit global is now defined // MusicKit global is now defined
function initMusicKit() { function initMusicKit() {
let parsedJson = JSON.parse(this.responseText) let parsedJson = JSON.parse(this.responseText);
MusicKit.configure({ MusicKit.configure({
developerToken: parsedJson.token, developerToken: parsedJson.token,
app: { app: {
name: 'Apple Music', name: "Apple Music",
build: '1978.4.1', build: "1978.4.1",
version: "1.0" version: "1.0",
}, },
sourceType: 24, sourceType: 24,
suppressErrorDialog: true suppressErrorDialog: true,
}).then(() => { }).then(() => {
function waitForApp() { function waitForApp() {
if (typeof app.init !== "undefined") { if (typeof app.init !== "undefined") {
app.init() app.init();
if (app.cfg.visual.window_background_style == "mica") { if (app.cfg.visual.window_background_style == "mica") {
app.spawnMica() app.spawnMica();
} }
} } else {
else {
setTimeout(waitForApp, 250); setTimeout(waitForApp, 250);
} }
} }
waitForApp() waitForApp();
}) });
} }
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
request.timeout = 5000; request.timeout = 5000;
request.addEventListener("load", initMusicKit); request.addEventListener("load", initMusicKit);
request.onreadystatechange = function (aEvt) { request.onreadystatechange = function (aEvt) {
if (request.readyState == 4) { if (request.readyState == 4) {
if (request.status != 200) if (request.status != 200) fallbackinitMusicKit();
fallbackinitMusicKit()
} }
}; };
request.open("GET", "https://api.cider.sh/v1/"); request.open("GET", "https://api.cider.sh/v1/");
@ -160,17 +159,14 @@ document.addEventListener('musickitloaded', function () {
// check for widevine failure and reconfigure the instance. // check for widevine failure and reconfigure the instance.
window.addEventListener("drmUnsupported", function () { window.addEventListener("drmUnsupported", function () {
initMusicKit() initMusicKit();
}); });
}); });
if ("serviceWorker" in navigator) {
if ('serviceWorker' in navigator) {
// Use the window load event to keep the page load performant // Use the window load event to keep the page load performant
window.addEventListener('load', () => { window.addEventListener("load", () => {
navigator.serviceWorker.register('sw.js?v=1'); navigator.serviceWorker.register("sw.js?v=1");
}); });
} }
@ -183,26 +179,29 @@ const getBase64FromUrl = async (url) => {
reader.onloadend = () => { reader.onloadend = () => {
const base64data = reader.result; const base64data = reader.result;
resolve(base64data); resolve(base64data);
} };
}); });
} };
function Clone(obj) { function Clone(obj) {
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));
} }
function uuidv4() { function uuidv4() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) (
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
); );
} }
function xmlToJson(xml) { function xmlToJson(xml) {
// Create the return object // Create the return object
let obj = {}; let obj = {};
if (xml.nodeType == 1) { // element if (xml.nodeType == 1) {
// element
// do attributes // do attributes
if (xml.attributes.length > 0) { if (xml.attributes.length > 0) {
obj["@attributes"] = {}; obj["@attributes"] = {};
@ -211,7 +210,8 @@ function xmlToJson(xml) {
obj["@attributes"][attribute.nodeName] = attribute.nodeValue; obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
} }
} }
} else if (xml.nodeType == 3) { // text } else if (xml.nodeType == 3) {
// text
obj = xml.nodeValue; obj = xml.nodeValue;
} }
@ -220,10 +220,10 @@ function xmlToJson(xml) {
for (var i = 0; i < xml.childNodes.length; i++) { for (var i = 0; i < xml.childNodes.length; i++) {
var item = xml.childNodes.item(i); var item = xml.childNodes.item(i);
var nodeName = item.nodeName; var nodeName = item.nodeName;
if (typeof (obj[nodeName]) == "undefined") { if (typeof obj[nodeName] == "undefined") {
obj[nodeName] = xmlToJson(item); obj[nodeName] = xmlToJson(item);
} else { } else {
if (typeof (obj[nodeName].push) == "undefined") { if (typeof obj[nodeName].push == "undefined") {
var old = obj[nodeName]; var old = obj[nodeName];
obj[nodeName] = []; obj[nodeName] = [];
obj[nodeName].push(old); obj[nodeName].push(old);
@ -234,7 +234,7 @@ function xmlToJson(xml) {
} }
console.log(obj); console.log(obj);
return obj; return obj;
}; }
async function asyncForEach(array, callback) { async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) { for (let index = 0; index < array.length; index++) {
@ -244,30 +244,33 @@ async function asyncForEach(array, callback) {
var checkIfScrollIsStatic = setInterval(() => { var checkIfScrollIsStatic = setInterval(() => {
try { try {
if (position === document.getElementsByClassName('lyric-body')[0].scrollTop) { if (
clearInterval(checkIfScrollIsStatic) position === document.getElementsByClassName("lyric-body")[0].scrollTop
) {
clearInterval(checkIfScrollIsStatic);
// do something // do something
} }
position = document.getElementsByClassName('lyric-body')[0].scrollTop position = document.getElementsByClassName("lyric-body")[0].scrollTop;
} catch (e) { } catch (e) {}
}
}, 50); }, 50);
// WebGPU Console Notification // WebGPU Console Notification
async function webGPU() { async function webGPU() {
try { try {
const currentGPU = await navigator.gpu.requestAdapter() const currentGPU = await navigator.gpu.requestAdapter();
console.log("WebGPU enabled on", currentGPU.name, "with feature ID", currentGPU.features.size) console.log(
"WebGPU enabled on",
currentGPU.name,
"with feature ID",
currentGPU.features.size
);
} catch (e) { } catch (e) {
console.log("WebGPU disabled / WebGPU initialization failed") console.log("WebGPU disabled / WebGPU initialization failed");
} }
} }
function isJson(item) { function isJson(item) {
item = typeof item !== "string" item = typeof item !== "string" ? JSON.stringify(item) : item;
? JSON.stringify(item)
: item;
try { try {
item = JSON.parse(item); item = JSON.parse(item);
@ -282,11 +285,56 @@ function isJson(item) {
return false; return false;
} }
webGPU().then() webGPU().then();
let screenWidth = screen.width; let screenWidth = screen.width;
let screenHeight = screen.height; let screenHeight = screen.height;
document.addEventListener('DOMContentLoaded', async function () { document.addEventListener("DOMContentLoaded", async function () {
// app.oobeInit() // app.oobeInit()
}) });
document.addEventListener(
"contextmenu",
function (e) {
if (
e.target.tagName.toLowerCase() == "textarea" ||
(e.target.tagName.toLowerCase() == "input" &&
e.target.type != "checkbox" &&
e.target.type != "radio" &&
e.target.disabled == false)
) {
e.preventDefault();
const menuPanel = {
items: {
cut: {
name: app.getLz("action.cut"),
action: function () {
document.execCommand("cut");
},
},
copy: {
name: app.getLz("action.copy"),
action: function () {
document.execCommand("copy");
},
},
paste: {
name: app.getLz("action.paste"),
action: function () {
document.execCommand("paste");
},
},
selectAll: {
name: app.getLz("action.selectAll"),
action: function () {
document.execCommand("selectAll");
},
},
},
}
app.showMenuPanel(menuPanel, e)
}
},
false
);