Filter Extra Flags

Filtering specific regional flags for int

  1. // ==UserScript==
  2. // @name Filter Extra Flags
  3. // @namespace http://vexxed.github.io/
  4. // @description Filtering specific regional flags for int
  5. // @include http*://boards.4chan.org/int/*
  6. // @include http*://boards.4chan.org/pol/*
  7. // @include http*://boards.4chan.org/bant/*
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  9. // @version 0.01
  10. // @grant none
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. //TODO: Make a native 4chan version, only filter and check new posts when updating
  15. $(window).load(function(){
  16. dBug("Document is ready!");
  17. var filteredRegions = ["California", "Iroquois"]; //replace these with any you like
  18. var regions = [];
  19.  
  20. document.addEventListener('ThreadUpdate', function (e) {
  21. getFlags();
  22. }, false);
  23.  
  24. function matchRegions(filteredFlags, flags){
  25. for (var i = flags.length - 1; i >= 0; i--) {
  26. for (var j = filteredFlags.length - 1; j >= 0; j--) {
  27. if (flags[i].children[0].title == filteredFlags[j]){
  28. dBug("filtered: " + filteredFlags[j]);
  29. if ( isVisible(flags[i].parentNode.parentNode.parentNode.previousSibling.children[0]))
  30. flags[i].parentNode.parentNode.parentNode.previousSibling.children[0].click();
  31. }
  32. }
  33. }
  34. };
  35.  
  36. function isVisible(e) {
  37. return !!( e.offsetWidth || e.offsetHeight || e.getClientRects().length );
  38. }
  39.  
  40. function getFlags(){
  41. regions = document.getElementsByClassName("extraFlag");
  42. matchRegions(filteredRegions, regions);
  43. };
  44.  
  45. function dBug(data){
  46. //console.log(data);
  47. };
  48.  
  49. setTimeout(function() {
  50. getFlags();
  51. }, 0);
  52. });