久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

代碼在瀏覽器控制臺中工作,但不在 Tampermonkey

Code working in browser console but not in tampermonkey(代碼在瀏覽器控制臺中工作,但不在 Tampermonkey 中)
本文介紹了代碼在瀏覽器控制臺中工作,但不在 Tampermonkey 中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試在

使用腳本

我想要什么

我已經檢查了 這個 但它并沒有解決我的問題.

有什么幫助嗎?提前致謝.

解決方案

大部分頁面都是動態加載的(AJAX 驅動),這意味著您的腳本通常會在您感興趣的節點之前完成運行,出現在頁面中/頁面上.

您必須使用 AJAX 感知技術,例如 waitForKeyElementsMutationObserver.

這里是一個完整的 Tampermonkey 腳本,它說明了這個過程:

//==UserScript==//@name _Lichess.org,榮耀選擇用戶//@match *://lichess.org/*//@require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js//@require https://gist.github.com/raw/2625891/waitForKeyElements.js//@grant GM_addStyle//@grant GM.getValue//==/用戶腳本==//- 需要@grant 指令來恢復正確的沙箱.waitForKeyElements ("a[href*='WaisKamal']", spiffifyLink);函數 spiffifyLink (jNode) {var oldHtml = jNode.html ();var newHtml = '<span class="title" data-title="GM" title="Grandmaster">GM</span>' + oldHtml;jNode.html (newHtml);}

<小時>

有關詳細信息,請參閱 其他答案關于選擇和使用 waitForKeyElements 和/與 jQuery 選擇器.

I am trying to run the following block of code on https://lichess.org/uZIjh0SXxnt5.

var x = document.getElementsByTagName("a");

for(var i = 0; i < x.length; i++) {
    if(x[i].href.includes("WaisKamal") && x[i].classList.contains("user_link")) {
        x[i].innerHTML = '<span class="title" data-title="GM" title="Grandmaster">GM</span> ' + x[i].innerHTML;
    }

    if(x[i].href.includes("WaisKamal") && x[i].classList.contains("text")) {
        x[i].innerHTML = '<span class="title" data-title="GM" title="Grandmaster">GM</span> ' + x[i].innerHTML;
        console.log(x[i]);
    }
}

I am using tampermonkey to automate the process. When the page loads, the first if statement runs correctly, but not the second one. However, when I run the second one from the browser console, it works fine.

Here is what the script does in more detail (I want to add those orange "GM"s):

Without the script

With the script

What I want

I have checked this but it didn't solve my problem.

Any help? Thanks in advance.

解決方案

Most of that page is loaded dynamically (AJAX-driven), which means that your script will normally finish running long before the nodes, that you are interested in, appear in/on the page.

You must use AJAX-aware techniques such as waitForKeyElements or MutationObserver.

Here's a complete Tampermonkey script that illustrates the process:

// ==UserScript==
// @name     _Lichess.org, Glorify select users
// @match    *://lichess.org/*
// @require  https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant    GM_addStyle
// @grant    GM.getValue
// ==/UserScript==
//- The @grant directives are needed to restore the proper sandbox.

waitForKeyElements ("a[href*='WaisKamal']", spiffifyLink);

function spiffifyLink (jNode) {
    var oldHtml = jNode.html ();
    var newHtml = '<span class="title" data-title="GM" title="Grandmaster">GM</span> ' + oldHtml;
    jNode.html (newHtml);
}


See this other answer for more information about choosing and using waitForKeyElements and/with jQuery selectors.

這篇關于代碼在瀏覽器控制臺中工作,但不在 Tampermonkey 中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 久久国产精品久久久久 | 久久久91精品国产一区二区三区 | 国产探花在线精品一区二区 | www国产成人免费观看视频,深夜成人网 | 免费看色| 国产成人久久精品一区二区三区 | 精品久久久久久久久久久院品网 | 久久精品亚洲一区二区三区浴池 | a久久| 国产伦精品一区二区三区视频金莲 | 精品在线一区 | 中文字幕av中文字幕 | 欧美成人精品激情在线观看 | 成人二区 | 日批av| 国产不卡在线观看 | 精品在线一区 | 国产免费一区二区三区 | 日日夜夜精品 | 国产精品99999999 | 亚洲欧美视频一区 | 免费一二区 | 免费黄色录像片 | 成人免费视频7777777 | 青春草在线 | 国产中文字幕在线观看 | 欧美一区二区三区的 | 精品一区二区三 | 国产在线视频一区二区 | 中文字幕成人av | 在线国产视频 | 国产激情91久久精品导航 | 久久精品二区亚洲w码 | 成人在线h | 亚洲精品成人av久久 | 欧美2区 | 国产一区二区三区四区 | 成人av免费网站 | 天堂成人av | 久久久精 | 一级黄在线观看 |