自动给 Google 搜索结果添加查看缓存功能

作者:matrix 发布时间:2024-07-12 分类:零零星星

google 搜索结果的查看缓存功能下线其实很久了,每次都得手动 `cache:https://www.hhtjim.com/` 就很麻烦。

有空搞了个油猴脚本能自动在Google搜索结果中添加 [Cache] 链接到该网页的缓存版本 🥳🥳 这就方便多了

安装地址

https://greasyfork.org/zh-CN/scripts/500422-google-cache-viewer

脚本代码

// ==UserScript==
// @name         Google cache viewer
// @namespace    http://hhtjim.com/
// @version      1.0.1
// @description  Automatically adds a cache link to Google Search results. / Google搜索结果中添加缓存按钮
// @author       Hootrix
// @include      https://www.google.tld/search?*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        // select containers `cite[role="text"]`
        const containers = document.querySelectorAll('.g.Ww4FFb.vt6azd.tF2Cxc.asEBEc');

        containers.forEach(container => {
            //const cite = container.querySelector('cite[role="text"]');
            let cites = container.querySelectorAll('cite[role="text"]');
            // last item
            let cite = cites[cites.length - 1];
            const link = container.querySelector('a[data-ved]');
            if (cite && cite.textContent.startsWith('http')) {
                //const url = cite.textContent;
                const url = link.href
                const cacheUrl = `https://webcache.googleusercontent.com/search?q=cache:${url}`;

                const cacheDiv = document.createElement('div');
                cacheDiv.className = '';  // class name  eFM0qc
                cacheDiv.innerHTML = `<a href="${cacheUrl}" target="_blank" style="visibility:visible;color: blue; margin-left: 10px;" rel="noopener">[Cache]</a>`;

                if (cite.parentElement) {
                    cite.parentElement.appendChild(cacheDiv);
                }
            }
        });
    });
})();

自动打码Twitter图片

作者:matrix 发布时间:2024-03-26 分类:零零星星

最近几年总是黄推泛滥,不管你有没有关注总会在评论区看到😂
网页刷推时要是看到就很尴尬了,索性把所有图片全部打码,鼠标悬浮才显示。
完美解决🍺🍺🍺

图片5765-自动打码Twitter图片

安装地址

https://greasyfork.org/zh-CN/scripts/492051-twitter-safeview-auto-blur-with-hover-reveal

脚本代码

// ==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       You
// @match        https://twitter.com/*
// @grant        none
// ==/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();
})();

博客标题下面的ajax加载一句话

作者:matrix 发布时间:2015-01-12 分类:Wordpress 兼容并蓄

博客LOGO下面的一句话功能是照搬philna2主题弄的,点击一下就更新一句话的内容,是很久前的弄的小功能,现在回忆一下简单步骤。给需要的一位童鞋。

1.在wordpress主题的functions.php中添加代码

function HHTJimSay(){
    $Sentence =
    '
    11111
    22222
    33333
    44444
    ';
    $words = explode("\n", $Sentence);
    $word = $words[ mt_rand(1, count($words) - 2) ];
    echo $word;
}
function _exitajax(){
exit();
}
function Is_AjaxURL() {
    if((isset($_GET['do']) && $_GET['do'] == 'ajax') ) {
        return true;
    }else{
        return false;
    }
}
/**
 * 通过USER_Agent判断是否为机器人.
 */
function is_bot(){
    $bots = array('Google Bot1' => 'googlebot', 'Google Bot2' => 'google', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'jeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot', 'Technorati' => 'technorati', 'Yahoo' => 'yahoo', 'Findexa' => 'findexa', 'NextLinks' => 'findlinks', 'Gais' => 'gaisbo', 'WiseNut' => 'zyborg', 'WhoisSource' => 'surveybot', 'Bloglines' => 'bloglines', 'BlogSearch' => 'blogsearch', 'PubSub' => 'pubsub', 'Syndic8' => 'syndic8', 'RadioUserland' => 'userland', 'Gigabot' => 'gigabot', 'Become.com' => 'become.com','Bot'=>'bot','Spider'=>'spider','yinheli_for_test'=>'dFirefox');
    $useragent = $_SERVER['HTTP_USER_AGENT'];
    foreach ($bots as $name => $lookfor) {
        if (stristr($useragent, $lookfor) !== false) {
            return true;
            break;
        }
    }
}
if(Is_AjaxURL() && !is_bot()){//存在_GET且不是机器
add_action('Ready','HHTJimSay');
add_action('Ready', '_exitAjax', 9999);
}
do_action( 'Ready');

说明:
用于ajax后台提取一句话函数
4-7行处自己添加需要显示的一句话

2.在header.php中,加载完jq之后的位置添加js代码

var blogURL="https://www.hhtjim.com";//网站域名  
$(function(){  
    function o(v){  
        url=v.u?v.u:blogURL+"?do=ajax";  
        if(v.fn){  
            var nowTime = new Date().getTime();  
            url+="&action="+v.fn+"&t="+nowTime  
        }  
        type=v.m?v.m:"GET";  
        data=v.d?v.d:null;  
        dataType=v.dt?v.dt:"html";  
        beforeSend=v.b?v.b:null;  
        error=v.e?v.e:function(){  
            alert(lang.commonError);  
            document.body.style.cursor="auto"  
        };  
        success=v.s?v.s:function(w){  
            alert(w)  
        };  
        $.ajax({  
            url:url,type:type,data:data,dataType:dataType,beforeSend:beforeSend,error:error,success:success  
        })  
    }  

    function u(){  
        var v=false;  
        var x=document.getElementById('HHTJimSay') ? $("#HHTJimSay") : $("#HHTJimSay_s") ;  
        var w="loading";  
        x.click(function(){  
            if(v){  
                return false  
            }  
            var z=function(){  
                x.hide(0,function(){  
                    x.attr('title','').html("").addClass(w).show();//0秒后出现漏斗  

                });  
                v=true  
            };  
            var y=function(){  
                x.html(lang.commonError);  
                x.removeClass(w);  
                v=false  
            };  
            var A=function(B){  
                setTimeout(function(){  
                    x.hide(0);  
                    x.attr('title','点击这里获取更新').html(B).removeClass(w).fadeIn("slow"); //show(300)改fadeIn("slow") 淡入  
                    v=false  
                }  
                ,3000)//3000 漏斗出现时间  
            };  
            o({  
                b:z,e:y,s:A,fn:"HHTJimSay"  
            });  
            return false  
        })  
    }  
    u();  
    function n(){  
        var w=$("#welcome_msg");  
        var v=$("#profile");  
        var m=$("#author");  
        $("#edit_profile").toggle(function(){  
            w.slideUp(200);  
            v.slideDown(200);  
            m.select();  
            return false  
        }  
        ,function(){  
            w.slideDown(200);  
            v.slideUp(200);  
            return false  
        })  
    }  
    n();  
});  

说明:修改第一行的网站域名

3.在header.php处需要显示的位置添加代码

<span id="HHTJimSay_s" title="点击这里获取更新" style="white-space: nowrap;" class="description"><?php HHTJimSay(); ?></span>

4.在style.css中添加样式代码

#HHTJimSay_s{background:url('data:image/gif;base64,R0lGODlhEAAQALMJALvM7rDE6aW86UV10leF2WWM2cXj/zNmzP///////wAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJAAAJACwAAAAAEAAQAAAENDDJCUoBM+tyTtGTMAgJ50mGNhxDUl2JIWciCaZgru/avPs+XZBHLOJuvSFKeQwec8oiKAIAIfkECQAACQAsAAAAABAAEAAABDcwyZlCoJiGc26WhrR1QEEAlKGKV8ERWIi5R/FhZYHefLLyv99N2CsaZRkkiLhU+iZCZ0xqxEQAACH5BAkAAAkALAAAAAAQABAAAAQ2MMlJq5XG3KlxF4NAZR01HENVUqC4vbAEFAWQZG9xHMW9VjpeLDGrDS8/jgq3/JWYNxj0eIkAACH5BAkAAAkALAAAAAAQABAAAAQ0MMlJq5XG3KlxT58XitXIbWhaBYGHBsfRZm/cqgmrAkUBlJZCrEDJjIQHAtDFI/w2NFwqAgAh+QQJAAAJACwAAAAAEAAQAAAENDDJSauVxtypcU+fF4rVyG1oimYpC5qUq84qLAxCzAJFASSDw6AkKRwOhcQtdzEiZzyfJQIAIfkECQAACQAsAAAAABAAEAAABDUwyUmrlcbcqXFPnxeK1chtaIpmKQualKtaQFEAc3EchTUSu14gQJoACLfAjghCKQ9M1fASAQAh+QQJAAAJACwAAAAAEAAQAAAENTDJSauVxtypcU+fF4rVyG2oBBQFkErFcRRolsRzra3t61+CgeAyGhwGlkwoOAR9TBTbDxUBACH5BAUAAAkALAAAAAAQABAAAAQ4MMlJq5XGXAlIAUk2aRRxHEWVkVJxpmoFFN82BYFNBWe+ibyD7yJK4HRIJCtGWVmczRFr+aQmLREAOw==') no-repeat 10000px 10000px;cursor:pointer;}
#HHTJimSay_s.loading{cursor:default;display:none;background-position:center center;width:18px;height:16px;}

JS的eval函数解密反混淆

作者:matrix 发布时间:2014-05-14 分类:零零星星

打开有些js文件看到的eval(function(p,a,c,k,e,d)开头,只有结尾部分有很多竖线|间隔的字符,这是eval混淆了的。想要查看原本的代码就需要反混淆。下面的html工具可以用到,不算是很全面,仅供参考。

html文件:

http://pan.baidu.com/s/1pJ8YhSJ
http://www.400gb.com/file/64636372
这个页面上加载起来估计有冲突,建议把html文件下载到本地打开使用。

参考:http://www.chinadmd.com/file/ciziaiisseupixiwiswtstpo_3.html

IE浏览器Ajax请求时304错误

作者:matrix 发布时间:2014-04-24 分类:Wordpress

IE浏览器Ajax请求时304错误

博客LOGO下面的一句话功能是按照philna2主题弄的,点击一下就更新内容。但是每次用IE浏览器点击获取都会停留在固定的一句话,F12之后才看到是304错误。客户端代码用的jq ajax()方法,理论上是支持各种浏览器的。

今天终于解决这个问题,都是狗日的IE浏览器缓存搞的。

原因

IE浏览器ajax时会缓存之前get请求过的URL内容,如果下次还请求那个URL就从本地缓存中取出,之后也就会停止ajax请求。所以会失败,总是停留在一个请求内容里。

解决办法

请求的URL地址中加上动态值,比如UNIX时间戳。

像这样的地址  http://127.0.0.1?do=ajax&t=这里为UNIX时间戳

UNIX时间戳每秒都在变化,每次请求地址的URL都不一样,IE也就缓存不到。

js代码参考:

var nowTime = new Date().getTime();

参考:

http://blog.csdn.net/puncha/article/details/17962623

php版本的charCodeAt()函数

作者:matrix 发布时间:2014-03-29 分类:兼容并蓄 零零星星

charCodeAt()函数方法可返回指定位置的字符的 Unicode 编码。这个返回值是 0 - 65535 之间的整数。
JavaScript里经常看到charCodeAt函数但有些时候需要转换为php,这下就哦豁了。php里没有这玩意~ 自己写又搞不来。

还好,网上有一大把的代码:


function get_bianma($str)//等同于js的charCodeAt() { $result = array(); for($i = 0, $l = mb_strlen($str, 'utf-8');$i < $l;++$i) { $result[] = uniord(mb_substr($str, $i, 1, 'utf-8')); } return join(",", $result); } function uniord($str, $from_encoding = false) { $from_encoding = $from_encoding ? $from_encoding : 'UTF-8'; if (strlen($str) == 1) return ord($str); $str = mb_convert_encoding($str, 'UCS-4BE', $from_encoding); $tmp = unpack('N', $str); return $tmp[1]; }

说明:

get_bianma(substr($f, $e, 1))等同于js代码$f.charCodeAt($e)

表示获取$f中的第$e个位置的字符的 Unicode 编码

ajax跨域请求json数据

作者:matrix 发布时间:2014-03-13 分类:零零星星

 

刚开始仅仅想获取一个他域的json数据,没想到牵扯到很多的问题。
每次都请求失败:
chrome面板的status为(canceled)

在Request Header这里显示CAUTION Provisional headers are shown

 

后来才知道是ajax跨域问题导致:

也就是ajax同源策略(同源是指域名,协议,端口相同)。
跨域可以实现在自己的网站之间传递数据。但是如果你想用“跨域”盗取其它网站的数据,那还是放弃吧。除非目标网站有给你提供JSONP的接口,或者有某些可以利用的漏洞,要不然真没什么办法实现。
跨域问题的产生,最主要原因是COOKIE的安全问题。因为COOKIE是属于一个域的,如果允许跨域,客户端浏览器上储存的COOKIE就可以被它的所有者之外的程序访问到。举个例子吧,假如没有跨域问题,我现在就可以给百度发送个HTTP请求,获取你在百度上登录的用户名。或者获取SessionID,直接冒充你的帐号登录。为了避免这些问题,所以跨域访问的限制是非常有必要的。

利用jsonp跨域

跨域必须要有回调函数的接口,这里用jsonp试试 阅读剩余部分 »

再改外链转换工具

作者:matrix 发布时间:2014-02-04 分类:零零星星

感觉以前的界面按钮有些小,正好改成3.0.3的css前端框架试试~。

web app新界面

>>外链转换工具

资源 :

Bootstrap中文网: http://www.bootcss.com/  里面各种开源,各种介绍~

百度CDN公共库:http://developer.baidu.com/wiki/index.php?title=docs/cplat/libs

用的其中Bootstrap v3.0.3:http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css

UI变动: 阅读剩余部分 »