Discussions » Development

A simple script to remove the posts by keywords in Baidu, effective but confused

§
Posted: 2019-09-03

A simple script to remove the posts by keywords in Baidu, effective but confused

// ==UserScript==
// @name       按关键词屏蔽贴吧帖子
// @namespace  Violentmonkey Scripts
// @match      *://tieba.baidu.com/f?*
// @grant      none
// @require    http://code.jquery.com/jquery-1.11.0.min.js
// ==/UserScript==

$(document).ready(function(){
  var lists = $("#thread_list > li");
  for(var i=1; i < lists.length; i++){
    var tit = lists[i].querySelector("a.j_th_tit");
    if(/(考研|租)/.test(tit.innerHTML)) {
      $(lists[i]).remove();
    }
  }
});

That's my script. Although it works, the pictures of every remaining posts can't load. help plz~

wOxxOmMod
§
Posted: 2019-09-03

Try removing @grant none, it's a special mode that makes the script run outside of the sandbox, which normally is not needed and often it's harmful as it may overwrite some of the global page stuff.

§
Posted: 2019-09-04

@wOxxOm Thanks for your reply. I have removed @grant none. I found when I activated this script, all the links on the page became invalid (no response when click it), and when I disactivated the script, the page returned to normal. What behaviors may causes this problem?

Post reply

Sign in to post a reply.