|
|
动机
看到@Makima老师编写的【脚本】去访客记录,因为这个脚本在查看主题、回复、记录、资料等时也会自动跳回删除足迹的首页,和我的需求并不完全符合,所以又写了一个在空间左上角添加按钮、点击才会触发的功能类似的脚本。
功能
这个脚本可以在浏览某个用户的空间时,在空间的左上角“返回首页”按钮右侧添加一个新的“删除足迹”按钮。点击这个按钮后就会自动跳转到后缀 &do=index&view=admin&additional=removevlog 的删除足迹页面。
代码
@Name @Match @Icon
- // ==UserScript==
- // @name 空间:添加删除足迹按钮
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description 在GameMale用户页面添加删除足迹按钮
- // @author You
- // @match https://www.gamemale.com/home.php?mod=space&uid=*
- // @match https://www.gamemale.com/space-uid-*.html
- // @match https://www.gamemale.com/?*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // 提取当前页面的UID
- function getCurrentUID() {
- const url = window.location.href;
- let uid = null;
- // 匹配三种URL格式
- const matches1 = url.match(/uid=(\d+)/);
- const matches2 = url.match(/space-uid-(\d+)\.html/);
- const matches3 = url.match(/[?&](\d+)/);
- if (matches1 && matches1[1]) {
- uid = matches1[1];
- } else if (matches2 && matches2[1]) {
- uid = matches2[1];
- } else if (matches3 && matches3[1]) {
- uid = matches3[1];
- }
- // 验证UID是否为5-6位数字
- if (uid && /^\d{5,6}$/.test(uid)) {
- return uid;
- }
- return null;
- }
- // 添加删除足迹按钮
- function addRemoveFootprintButton(uid) {
- const toptb = document.getElementById('toptb');
- if (!toptb) return;
- const returnHomeLink = toptb.querySelector('a[href*="home.php?mod=space&do=home"]');
- if (!returnHomeLink) return;
- // 创建分隔符
- const pipe = document.createElement('span');
- pipe.className = 'pipe';
- pipe.textContent = '|';
- // 创建删除足迹链接
- const removeLink = document.createElement('a');
- removeLink.href = `https://www.gamemale.com/home.php?mod=space&uid=${uid}&do=index&view=admin&additional=removevlog`;
- removeLink.className = 'remove-footprint';
- removeLink.textContent = '删除足迹';
- removeLink.style.cursor = 'pointer';
- // 插入到返回首页按钮后面
- returnHomeLink.parentNode.insertBefore(pipe, returnHomeLink.nextSibling);
- returnHomeLink.parentNode.insertBefore(removeLink, pipe.nextSibling);
- }
- // 主函数
- function main() {
- const uid = getCurrentUID();
- if (uid) {
- addRemoveFootprintButton(uid);
- }
- }
- // 等待DOM加载完成
- if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', main);
- } else {
- main();
- }
- })();
复制代码
来自群组: 星象占卜 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
查看全部评分
|