-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgwScriptHelperFunctions.user.js
55 lines (47 loc) · 1.39 KB
/
gwScriptHelperFunctions.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ==UserScript==
// @name GlyphWiki script helper - functions
// @version 2023.01.01
// @namespace szc
// @description -
// @match *://glyphwiki.org/wiki/*
// @match *://*.glyphwiki.org/wiki/*
// @grant none
// @inject-into content
// ==/UserScript==
unsafeWindow.SH = {};
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard
unsafeWindow.SH.updateClipboard = function(text) {
navigator.clipboard.writeText(text).then(
function() {
//console.log();
},
function() {
console.log('Could not write to clipboard! ' + text);
}
);
}
// Extract data from a page name
unsafeWindow.SH.analyzeName = function(name) {
let data = {};
name = name.match(/^(.+:)?(.+_)?(.*?)(@.+)?$/);
data["ns"] = (name[1] && name[1].slice(0, -1) || "glyph");
data["userGlyphUser"] = (name[2] && name[2].slice(0, -1));
data["userGlyphName"] = name[3];
data["revision"] = name[4];
data["name"] = (name[2] || "") + name[3];
return data;
}
unsafeWindow.SH.nameToUnicode = function(name) {
return name
.replace(/-?u([0-9a-f]{4,})/g, function(_, hex) {
return String.fromCodePoint('0x' + hex);
})
.replace(/-?cdp-([0-9a-f]{4,})/g, '〓')
;
}
unsafeWindow.SH.removeNameSuffix = function(name) {
if (name.match(/^(cdp-|u[0-9a-f]{4,})/)) {
return name.replace(/(-(var|itaiji)-\d{3}|-([a-z]{1,2}|)(\d{2}|))+$/g, '');
}
return name;
}