我正在編寫一個腳本,它改變了我使用了很多網站的消息系統。它在每個消息線程的頂部添加一個按鈕。點擊後,它會自動移至線程中最新的消息。如何在執行php後獲取用戶腳本進行加載?
我遇到的問題是消息是由php加載和腳本在消息加載之前觸發。該站點也不會同時加載所有消息線程。它會加載10個左右,然後當您向下滾動時會加載更多。有沒有辦法讓按鈕加載每個消息線程,或者我是否爲無法達到的目標拍攝?
// ==UserScript==
// @name Imgur - Message Viewer
// @namespace Basion
// @description It skips to the bottom of the most recent message
// @author Basion
// @include http://imgur.com/*
// @include https://imgur.com/*
// @include http://*.imgur.com/*
// @include https://*.imgur.com/*
// @run-at document-end
// ==/UserScript==
var messages = document.getElementsByClassName("thread-wrapper");
var newA = document.createElement('a');
for (var i = 0; i < messages.length; i++) {
newA.addEventListener("click", scrollToMessage(i), true);
newA.innerText = "Go to Newest Message";
messages[i].appendChild(newA);
}
function scrollToMessage(id) {
var newMessages = document.getElementsByClassName('thread-wrapper');
newMessages[id].scrollIntoView(false);
}
你能從你添加一些源代碼? – reporter
我們可以看看您實際上想要使用該腳本的網站嗎?新內容如何加載?您可以考慮在執行前等待1秒鐘。或者,也許在點擊一個按鈕之後,腳本每秒鐘計算一次線程數。如果線程數量增加(即成功加載),則滾動至該值。 – kevinamadeus
@kevinamadeus我想在[Imgur](http://www.imgur.com)上使用它您必須創建一個帳戶才能看到消息系統。我相信你也可以發送消息給自己,如果這能幫助你理清一點。 – user2424715