Skip to content

Instantly share code, notes, and snippets.

@Hootrix
Last active April 9, 2024 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hootrix/024e64aac9dea1d69080ab647931485e to your computer and use it in GitHub Desktop.
Save Hootrix/024e64aac9dea1d69080ab647931485e to your computer and use it in GitHub Desktop.
Tampermonkey script

自用油猴脚本 Tampermonkey script

// ==UserScript==
// @name Google continue 自动重试
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 刷新页面让脚本自动重试www.google.com/sorry/index?continue=XXX拦截的网址。避免google自动打开会空白需要手动输入url的问题。
// @author qwertyuiop6
// @match https://www.google.com/sorry/index?continue=*
// @grant none
// @downloadURL https://gist.github.com/Hootrix/024e64aac9dea1d69080ab647931485e/raw/19016d685e5320fee0f511e0062da91da8c4c7b7/TwitterSafeView.user.js
// ==/UserScript==
(function(){
function parse_url(url) {
return [...new URL(url).searchParams].reduce(
(cur, [key, value]) => ((cur[key] = value), cur),
{}
);
}
var url = parse_url(document.location.href)
if(url.continue) document.location.href = url.continue;
})();
// ==UserScript==
// @name Twitter SafeView: Auto-Blur with Hover Reveal
// @namespace http://hhtjim.com/
// @version 1.0
// @description 自动打码推特所有图片,悬停时才显示完整清晰图像,避免黄图泛滥的尴尬。Automatically blurs all images and displays full clear images only when hovering.
// @author Hootrix
// @match https://twitter.com/*
// @grant none
// @license GPLv3
// ==/UserScript==
(function() {
'use strict';
const debounceDelay = 100; // milliseconds
// Debounce function to limit the rate of execution
function debounce(func, delay) {
let debounceTimer;
return function() {
const context = this;
const args = arguments;
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => func.apply(context, args), delay);
};
}
let mouseX = 0, mouseY = 0;
document.addEventListener('mousemove', debounce(function(e) {
mouseX = e.clientX;
mouseY = e.clientY;
updateImageBlur();
}, debounceDelay));
document.addEventListener('scroll', debounce(function(e) {
updateImageBlur();
}, debounceDelay));
// Function to check if the mouse is over the element
function isMouseOverElement(element) {
const rect = element.getBoundingClientRect();
return mouseX > rect.left && mouseX < rect.right && mouseY > rect.top && mouseY < rect.bottom;
}
// Function to update image blur
function updateImageBlur() {
// console.log('updateImageBlur')
//列表
document.querySelectorAll('article[data-testid="tweet"]').forEach(function(tweetDiv) {
// Apply or remove blur based on mouse position
if (isMouseOverElement(tweetDiv)) {
closeBlur(tweetDiv)
} else {
applyBlur(tweetDiv)
}
});
}
// Apply blur to the div and nested img
const applyBlur = (document) => {
// 推文
document.querySelectorAll('div[data-testid="tweetPhoto"], div[data-testid="card.layoutLarge.media"]').forEach(function(div) {
div.style.filter = 'blur(8px)';
const img = div.querySelector('img');
if (img) img.style.filter = 'blur(8px)';
});
};
const closeBlur = (document) => {
document.querySelectorAll('div[data-testid="tweetPhoto"], div[data-testid="card.layoutLarge.media"]').forEach(function(div) {
div.style.filter = '';
const img = div.querySelector('img');
if (img) img.style.filter = '';
});
};
// Observe for changes in the document
const observer = new MutationObserver(debounce(function() {
updateImageBlur();
},debounceDelay));
// Configuration of the observer
const config = { childList: true, subtree: true };
// var target = document.querySelector('section[aria-labelledby="accessible-list-1"]')
var target = document.body
// Start observing the target node for configured mutations
if(target){
observer.observe(target, config);
}
// Initial application of blur to images
updateImageBlur();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment