Auto-Click Blogger Sensitive Content Button

Automatically clicks through sensitive content warnings on Blogger

  1. // ==UserScript==
  2. // @name Auto-Click Blogger Sensitive Content Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Automatically clicks through sensitive content warnings on Blogger
  6. // @author You
  7. // @match *://*.blogger.com/*
  8. // @match *://*.blogspot.com/*
  9. // @grant none
  10. // @license CC BY-NC-SA 4.0
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const MAX_ATTEMPTS = 5;
  17. const ATTEMPT_INTERVAL = 1000;
  18. const MAX_OBSERVE_TIME = 10000;
  19. let attempts = 0;
  20.  
  21. function clickThroughWarning() {
  22. const buttonSelectors = [
  23. 'a.maia-button.maia-button-primary',
  24. 'a[text="I UNDERSTAND AND I WISH TO CONTINUE"]',
  25. 'div#maia-main p a.maia-button.maia-button-primary'
  26. ];
  27.  
  28. for (const selector of buttonSelectors) {
  29. const buttons = document.querySelectorAll(selector);
  30. for (const button of buttons) {
  31. if (button.textContent.includes('I UNDERSTAND AND I WISH TO CONTINUE')) {
  32. button.click();
  33. return true;
  34. }
  35. }
  36. }
  37.  
  38. const xpathResult = document.evaluate(
  39. '/html/body/div[2]/p[2]/a[1]',
  40. document,
  41. null,
  42. XPathResult.FIRST_ORDERED_NODE_TYPE,
  43. null
  44. );
  45.  
  46. if (xpathResult.singleNodeValue) {
  47. xpathResult.singleNodeValue.click();
  48. return true;
  49. }
  50.  
  51. return false;
  52. }
  53.  
  54. function attemptClick() {
  55. if (attempts >= MAX_ATTEMPTS) {
  56. return;
  57. }
  58.  
  59. attempts++;
  60. if (!clickThroughWarning() && attempts < MAX_ATTEMPTS) {
  61. setTimeout(attemptClick, ATTEMPT_INTERVAL);
  62. }
  63. }
  64.  
  65. function initObserver() {
  66. const observer = new MutationObserver((mutations) => {
  67. if (clickThroughWarning()) {
  68. observer.disconnect();
  69. return;
  70. }
  71. });
  72.  
  73. observer.observe(document.body, {
  74. childList: true,
  75. subtree: true
  76. });
  77.  
  78. setTimeout(() => {
  79. observer.disconnect();
  80. }, MAX_OBSERVE_TIME);
  81. }
  82.  
  83. attemptClick();
  84. initObserver();
  85. })();