我正在尝试在使用AJAX的页面上使用GreaseMonkey。我发现似乎是等待和评估元素的解决方案,因为它们出现在“waitForKeyElements”中
但是,我的控制台返回“waitForKeyElements is undefined”
这是代码:
// ==UserScript==
// @name SalesForce helper
// @namespace https://c.na3.visual.force.com*
// @include https://c.na3.visual.force.com*
// @include https://na3.salesforce.com/*
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
// ==/UserScript==
if(window.location.href.match("salesforce.com/500?")){
waitForKeyElements(".listBody div",Greasemonkey_main);
}
function Greasemonkey_main () {
alert(window.location.href);
if(window.location.href.match("salesforce.com/500?")){
var firstWords = ["Edit","Base","Accelerated","EU","GoLive","Redesign","Report"]
var divs = document.getElementsByTagName("div");
for(var i = 0;i < divs.length;i++){
var did = divs[i].id;
if(did.indexOf("CASES_SUBJECT") > 0){
var dSpan = divs[i].getElementsByTagName("span")[0];
var subject = divs[i].getElementsByTagName("span")[0].innerHTML.split(" ")[0];
if(firstWords.indexOf(subject) < 0){
//alert("howdy = " + subject);
dSpan.style = "background-color:yellow";
}
}
}
}
}
答案 0 :(得分:2)
我明白了。在我发现的所有这个函数的研究和示例中,我从未意识到它是一个需要包含的单独脚本。
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js