[英]Searching for a specific string using JavaScript and greasemonkey
到目前为止,我一直在尝试实现以下内容并收集了这小段代码。
去做 :
搜索单词“ Block”和“ Own”(如果两者同时存在),然后弹出一个警告框“ says both are found”
如果仅找到“阻止”,则抛出警告框“仅发现阻止”
如果仅找到“ own”和“ Cool”一词,则引发警报“发现own n cool”
同样,所有警报框都应具有“确认按钮”,当您再次单击该按钮时,应带有“确定”按钮,显示“您确定已完成吗?”。
示例代码为:
if (/Text you are looking for/i.test (document.body.innerHTML) )
{
alert ("Found it!");
}
function findAndAlert(element){
var foundBlock = false,
foundOwn = false,
foundCool = false;
if (element.match(/block/i) foundBlock = true;
if (element.match(/own/i) foundOwn = true;
if (element.match(/cool/i) foundCool = true;
if (foundBlock and foundOwn) alert('Both are found');
else if (foundBlock && !foundOwn) alert('Only block was found');
else if ( foundOwn && foundCool) alert('Found own and cool');
}
findAndAlert(document.body.innerHTML)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.