Appearance
JSON
提取网页标题、网址为 JSON 格式文本。
// ==UserScript==
// @name 网页
// @namespace Monkey
// @version 2049-10-01
// @description 网页
// @author 白马
// @run-at document-end
// @match *
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
// 创建按钮
const btn = document.createElement('button');
btn.innerText = '📋';
// 按钮样式
btn.style.position = 'fixed';
btn.style.top = '80px';
btn.style.right = '20px';
btn.style.zIndex = 99;
btn.style.padding = '10px 10px';
// 点击事件
btn.onclick = function() {
// 生成对象,写入剪贴板
const obj = {};
obj.name = document.title;
obj.url = window.location.href;
const text = JSON.stringify(obj);
GM_setClipboard(text);
// 反馈成功
const originalText = btn.innerText;
btn.innerText = '✅';
// 1 秒后恢复
setTimeout(() => {
btn.innerText = originalText;
}, 1000);
};
// 添加到页面
document.body.appendChild(btn);
})();提取列表,转化为 JSON 格式文本。
// ==UserScript==
// @name 列表Shop
// @namespace Monkey
// @version 2049-10-01
// @description 列表
// @author 白马
// @match https://b.com/shop/
// @grant GM_setClipboard
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
// 创建按钮
const btn = document.createElement('button');
btn.innerText = '📋';
// 按钮样式
btn.style.position = 'fixed';
btn.style.top = '40px';
btn.style.right = '20px';
btn.style.zIndex = 99;
btn.style.padding = '10px 10px';
// 点击事件
btn.onclick = function() {
// 生成对象,写入剪贴板
const items = document.querySelector('ul.List').querySelectorAll('li');
const arr = [];
for (let i of items) {
const obj = {};
obj.name = i.querySelector('.name').textContent;
obj.type = i.querySelector('.type').textContent;
arr.push(obj);
}
const text = JSON.stringify(arr);
GM_setClipboard(text);
// 反馈成功
const originalText = btn.innerText;
btn.innerText = '✅';
// 1 秒后恢复
setTimeout(() => {
btn.innerText = originalText;
}, 1000);
};
// 添加到页面
document.body.appendChild(btn);
})();网页内容滚动加载,支持分类筛选,不支持排序。提取内容,转化为 JSON 格式文本。
// ==UserScript==
// @name 列表Series
// @namespace Monkey
// @version 2049-10-01
// @description 列表
// @author 白马
// @run-at document-idle
// @match https://m.a.cn/series/
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
// 创建按钮
const btn = document.createElement('button');
btn.innerText = '📋';
// 按钮样式
btn.style.position = 'fixed';
btn.style.top = '40px';
btn.style.right = '20px';
btn.style.zIndex = 99;
btn.style.padding = '10px 10px';
// 点击事件
btn.onclick = function() {
// 生成对象,写入剪贴板
const list = document.querySelector('.list');
const items = list.querySelectorAll('.item');
const arr = [];
for (let i of items) {
const obj = {};
obj.id = i.getAttribute('data-index');
obj.name = i.querySelector('h2').textContent;
obj.url = i.querySelector('a').href;
arr.push(obj);
}
const text = JSON.stringify(arr);
GM_setClipboard(text);
// 反馈成功
const originalText = btn.innerText;
btn.innerText = '✅';
// 1 秒后恢复
setTimeout(() => {
btn.innerText = originalText;
}, 1000);
};
// 添加到页面
document.body.appendChild(btn);
})();多站点提取数据。
// ==UserScript==
// @name 提取数据
// @namespace Monkey
// @version 2049-10-01
// @description 提取数据
// @author 白马
// @match https://b.com/shop/
// @match https://m.a.cn/series/
// @grant GM_setClipboard
// @run-at document-idle
// ==/UserScript==
// 站点1
function shop() {
const items = document.querySelector('ul.List').querySelectorAll('li');
const arr = [];
for (let i of items) {
const obj = {};
obj.name = i.querySelector('.name').textContent;
obj.type = i.querySelector('.type').textContent;
arr.push(obj);
}
return arr;
}
// 站点2
function series() {
const list = document.querySelector('.list');
const items = list.querySelectorAll('.item');
const arr = [];
for (let i of items) {
const obj = {};
obj.id = i.getAttribute('data-index');
obj.name = i.querySelector('h2').textContent;
obj.url = i.querySelector('a').href;
arr.push(obj);
}
return arr;
}
(function() {
'use strict';
const href = window.location.href;
const dict = {
'https://b.com/shop/': shop,
'https://m.a.cn/series/': series,
}
// 不匹配则不运行
let flag = 0;
let func;
for (const [k, v] of Object.entries(dict)) {
if (href.startsWith(k)) {
flag = 1;
func = v;
break;
}
}
if (flag === 0) {
return;
}
// 创建按钮
const btn = document.createElement('button');
btn.innerText = '📋';
// 按钮样式
btn.style.position = 'fixed';
btn.style.top = '40px';
btn.style.right = '20px';
btn.style.zIndex = 99;
btn.style.padding = '10px 10px';
// 点击事件
btn.onclick = function() {
const text = JSON.stringify(func());
GM_setClipboard(text);
// 反馈成功
const originalText = btn.innerText;
btn.innerText = '✅';
// 1 秒后恢复
setTimeout(() => {
btn.innerText = originalText;
}, 1000);
};
// 添加到页面
document.body.appendChild(btn);
})();