Greasy Fork is available in English.
自动按下B键当URL包含 https://live.douyin.com/ 时,并点击特定按钮并删除特定内容
当前为
// ==UserScript==
// @name Douyin live stream optimization(优化网页)
// @namespace http://tampermonkey.net/
// @version 0.7
// @description 自动按下B键当URL包含 https://live.douyin.com/ 时,并点击特定按钮并删除特定内容
// @match https://*.douyin.com/*
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 模拟按下 B 键
function simulateBKeyPress() {
var event = new KeyboardEvent('keydown', {
key: 'b',
code: 'KeyB',
keyCode: 66, // B 键的键码
charCode: 0,
which: 66, // B 键的键码
shiftKey: false,
ctrlKey: false,
metaKey: false,
bubbles: true // 事件是否应该冒泡
});
document.dispatchEvent(event);
console.log('模拟按下 B 键');
}
// 点击按钮
function clickButton() {
var button = document.querySelector('.psKR9RS0 .WoNKVQmY.Z20k_Nsy');
if (button) {
button.click();
console.log('按钮已点击');
} else {
console.log('按钮未找到');
}
}
// 删除特定的礼物容器
function removeGiftItems() {
var giftContainer = document.querySelector('.fIHFYwJt[data-e2e="gifts-container"]');
if (giftContainer) {
giftContainer.remove();
console.log('礼物容器已删除');
} else {
console.log('未找到礼物容器');
}
}
function removeNewElement1() {
var newElement1 = document.querySelector('.LE4P00KT');
if (newElement1) {
newElement1.remove();
console.log('新的指定元素 1 已删除');
} else {
console.log('未找到新的指定元素 1');
}
}
// 删除特定的 HTML 内容
function removeSpecialContent() {
var specialContents = document.querySelectorAll('div._192Y0el > div.ljM5iqdR');
specialContents.forEach(function(content) {
content.remove();
});
console.log('特殊内容已删除');
// 删除新的指定元素 1
var newElement1 = document.querySelector('.LE4P00KT');
if (newElement1) {
newElement1.remove();
console.log('新的指定元素 1 已删除');
} else {
console.log('未找到新的指定元素 1');
}
// 删除新的指定元素 2
var newElement2 = document.querySelector('.mDjtvQMS.GiftEffectPlugin');
if (newElement2) {
newElement2.remove();
console.log('新的指定元素 2 已删除');
} else {
console.log('未找到新的指定元素 2');
}
// 删除新的指定元素 3
var newElement3 = document.querySelector('.mDjtvQMS.GiftEffectPlugin');
if (newElement3) {
newElement3.remove();
console.log('新的指定元素 3 已删除');
} else {
console.log('未找到新的指定元素 3');
}
}
// 判断 URL 是否包含特定字符串
if (window.location.href.includes("https://live.douyin.com/")) {
setTimeout(simulateBKeyPress, 5000); // 延迟5秒按下 B 键
setTimeout(clickButton, 5000); // 延迟5秒点击按钮,确保按键事件触发之后
setTimeout(removeGiftItems, 5000); // 延迟5秒删除礼物容器,确保前面的操作已完成
setTimeout(removeSpecialContent, 5000); // 延迟5秒删除特殊内容
setInterval(removeNewElement1, 1000);
}
})();