[英]Removing specific elements from a webpage with a script?
I currently use : 我目前使用:
"javascript:document.body.contentEditable%20=%20'true';%20document.designMode='on';%20void%200" “JavaScript的:document.body.contentEditable%20 =%20'true ';%20document.designMode =' 上';%20void%200"
To remove certain elements of a webpage. 删除网页的某些元素。 The page is a monitoring view for several alarms. 该页面是多个警报的监视视图。 I am required to monitor only a portion of them. 我只需要监控其中的一部分。 I have been using the above script to delete the views I don't need. 我一直在使用上面的脚本来删除我不需要的视图。 I'm wondering if there is a better way than manually "deleting" them every day. 我想知道是否有更好的方法,而不是每天手动“删除”它们。
Could I use the above script as a base to specify these elements and remove them all at once? 我可以使用上面的脚本作为基础来指定这些元素并一次性删除它们吗? I'm a bit of a rookie with this so any and all help is appreciated. 我有点像这样的新秀,所以任何和所有的帮助都表示赞赏。
javascript: var image_x = document.getElementById('ID'); javascript:var image_x = document.getElementById('ID'); image_x.parentNode.removeChild(ID); image_x.parentNode.removeChild(ID);
Edit the ID; 编辑ID; Copy and Paste and edit as many times as are required. 根据需要复制和粘贴并编辑多次。 It's bulky and ugly for what I needed but it works as one Bookmark in Chrome. 它对于我需要的东西来说是笨重而丑陋的,但它在Chrome中作为一个书签起作用。
You can use Greasemonkey on Firefox or Tampermonkey on Chrome. 您可以在Chrome上使用Greasemonkey ,也可以在Chrome上使用Tampermonkey 。 Either you choose, the following script will work. 您选择,以下脚本将起作用。 You must install the extension in your browser. 您必须在浏览器中安装扩展程序。 You then need to replace the URL from the script http://yoursite.com/
with your URL, add all id's to the array, add the script to the extension and it will automatically do the work. 然后,您需要使用URL替换脚本http://yoursite.com/
中的URL,将所有ID添加到数组中,将脚本添加到扩展中,它将自动完成工作。 No click on a bookmark necessary. 不要点击必要的书签。
// ==UserScript==
// @name CleanUp
// @namespace cleanup
// @include http://yoursitehere.com/
// @version 1
// @grant none
// ==/UserScript==
var removables = ['aus', 'bak', 'bhm', 'can'];//add more id's here following the pattern
for (var i = 0; i < removables.length; i++) {
var element = document.getElementById(removables[i]);
if (element) {
element.parentNode.removeChild(element);
}
}
If you want to stick to the bookmarklet, I have adapted it for you: 如果您想坚持使用书签,我已经为您调整了它:
javascript: function run() { var r = ['aus', 'bak', 'bhm', 'can']; for (var i = 0; i < r.length; i++) { var e = document.getElementById(r[i]); if (e) { e.parentNode.removeChild(e); } }; }; run();
Here too, you must update the list of id's to include all you want. 在这里,您还必须更新ID列表以包含您想要的所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.