-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempermonkey.user.js
More file actions
145 lines (120 loc) · 4.17 KB
/
tempermonkey.user.js
File metadata and controls
145 lines (120 loc) · 4.17 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// ==UserScript==
// @name Copy Judul
// @namespace http://tampermonkey.net/
// @version 1.7
// @description Untuk pribadi dan website tertentu
// @match *://*/*
// @grant GM_setClipboard
// ==/UserScript==
(function () {
'use strict';
let shortcutsActive = false;
let shortcutMap = {};
let shortcutLabels = [];
// buffer untuk shortcut multi-digit (a1, a2, dst)
let keyBuffer = '';
let bufferTimer = null;
function notify(msg) {
const n = document.createElement('div');
n.textContent = msg;
n.style.position = 'fixed';
n.style.top = '10px';
n.style.right = '10px';
n.style.background = 'yellow';
n.style.padding = '5px 10px';
n.style.border = '1px solid black';
n.style.zIndex = 9999;
document.body.appendChild(n);
setTimeout(() => n.remove(), 2000);
}
function generateShortcuts(n) {
const chars = 'asdfghjklqwertyuiopzxcvbnm';
let result = [];
for (let i = 0; i < n; i++) {
result.push(
chars[i % chars.length] +
(i >= chars.length ? Math.floor(i / chars.length) : '')
);
}
return result;
}
function copyToClipboard(text) {
GM_setClipboard(text);
notify(`Copied: ${text}`);
}
function activateShortcuts() {
if (shortcutsActive) return;
shortcutsActive = true;
const titles = document.querySelectorAll('#dataTable td.sorting_1 span');
if (!titles.length) {
notify("Tidak ada judul ditemukan!");
shortcutsActive = false;
return;
}
const shortcuts = generateShortcuts(titles.length);
shortcutMap = {};
shortcutLabels = [];
titles.forEach((title, index) => {
const shortcut = shortcuts[index];
shortcutMap[shortcut] = title.innerText;
const label = document.createElement('span');
label.textContent = `[${shortcut}]`;
label.style.color = 'red';
label.style.fontWeight = 'bold';
label.style.marginLeft = '5px';
title.parentElement.appendChild(label);
shortcutLabels.push(label);
});
document.addEventListener('keydown', handleKeydown);
notify("Shortcut ON (Shift+C untuk OFF)");
}
function deactivateShortcuts() {
shortcutsActive = false;
shortcutMap = {};
keyBuffer = '';
shortcutLabels.forEach(label => label.remove());
shortcutLabels = [];
document.removeEventListener('keydown', handleKeydown);
notify("Shortcut OFF (Shift+C untuk ON)");
}
function handleKeydown(e) {
const activeTag = document.activeElement.tagName;
if (activeTag === 'INPUT' || activeTag === 'TEXTAREA') return;
const key = e.key.toLowerCase();
// hanya terima huruf & angka
if (!/^[a-z0-9]$/.test(key)) return;
keyBuffer += key;
clearTimeout(bufferTimer);
bufferTimer = setTimeout(() => {
if (shortcutMap[keyBuffer]) {
copyToClipboard(shortcutMap[keyBuffer]);
}
keyBuffer = '';
}, 300);
}
// Shift + C = toggle shortcut
document.addEventListener('keydown', function (e) {
const activeTag = document.activeElement.tagName;
if (activeTag === 'INPUT' || activeTag === 'TEXTAREA') return;
if (e.shiftKey && e.key.toLowerCase() === 'c') {
observeTable(() => {
shortcutsActive ? deactivateShortcuts() : activateShortcuts();
});
}
});
function observeTable(callback) {
const table = document.querySelector('#dataTable');
if (!table) {
notify("Menunggu tabel muncul...");
const obs = new MutationObserver((_, obs) => {
if (document.querySelector('#dataTable')) {
obs.disconnect();
callback();
}
});
obs.observe(document.body, { childList: true, subtree: true });
} else {
callback();
}
}
})();