相关疑难解决方法(0)

除非刷新页面,否则 Grease/tampermonkey 脚本无法工作

我经常光顾一个论坛,该论坛以一种可怕的方式忽视用户。如果您将某人置于忽略状态,则几乎会使该用户的存在更加普遍。

所以我写了这个来完全隐藏它们:

// ==UserScript==
// @name         Freddie
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  hide annoying forum users
// @author       You
// @match        http://www.scout.com/college/kansas/forums/*
// @grant        none
// ==/UserScript==
/* jshint -W097 */

'use strict';

function checkForDiv() { // crappy workaround function to wait for AJAX content      
    if (!document.getElementById("wrapper")) {        
        setTimeout(checkForDiv, 300);   
    } else {       
        checkNames();   
    }
}

function checkNames() {  
    var mybannedList = ["Pyros", "GOHawksGators", "th30r3o"]; // add usernames  here
    var nms = document.body.querySelectorAll('a.authName'), i = 0, len …
Run Code Online (Sandbox Code Playgroud)

javascript greasemonkey tampermonkey

6
推荐指数
1
解决办法
3114
查看次数

Vue - 在没有 VueRouter 的情况下观看 url

是否可以在不包含 VueRouter 的情况下对 Vue 组件中的 URL 更改做出反应?

如果存在 VueRouter,我们可以查看 $route,但是,我的应用程序不依赖于 VueRouter。

export default {
    watch: { '$route': route => console.log(window.location.href) }
}
Run Code Online (Sandbox Code Playgroud)

url watch vue.js

6
推荐指数
1
解决办法
1万
查看次数

如何使用 JavaScript 观察 URL 的变化?

Window 事件文档popstate说明:

请注意,仅调用history.pushState()or history.replaceState()不会触发popstate事件。该 popstate事件将通过执行浏览器操作触发,例如单击后退或前进按钮(或调用history.back()history.forward()在 JavaScript 中)。

我需要一种在 URL 更改时通过不触发popstate事件的方式(例如history.replaceState())来执行某些代码的方法。最好使用 MutationObserver API [1],并且绝对不要每 x 秒轮询一次 URL。

此外,hashchange不会这样做,因为我必须对URL 中的每个更改采取行动,而不仅仅是哈希部分。

那可能吗?


[1]在另一个问题上解释为什么 MutationObserver API 对此不起作用。


(其他)相关问题:

javascript events mutation-observers

4
推荐指数
1
解决办法
1286
查看次数

当发生任何变化时如何检测当前URL

我正在使用"document.location.hash"剥离网址,并尝试检查当前网址留下的内容.我不想使用任何插件,也不想学习点击等触发事件的结果.需要立即学习url变化和现代.

jQuery的:

$(function() {
    $(document).location().change(function() {//this part is not working
        var anchor = document.location.hash;
        if( anchor === '#one' ) {
            alert('current url = #one');
        }else if ( anchor === '#two' ) {
            alert('current url = #two');
        }else if ( anchor === '#three' ) {
            alert('current url = #three');
        }
        console.log(anchor);
    });
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<a href="#one">one</a>
<a href="#two">two</a>
<a href="#three">three</a>
Run Code Online (Sandbox Code Playgroud)

深注:我已经阅读了这些问题并且cout找到了我要找的内容: 如何检测JavaScript中的URL更改 + 如何更改javascript中的当前URL?

url jquery location href

3
推荐指数
1
解决办法
1万
查看次数