|
// ==UserScript== |
|
// @name Auto-dismiss Data Classification Banner in Google Docs |
|
// @namespace http://tampermonkey.net/ |
|
// @version 1.1.1 |
|
// @updateURL https://gist.githubusercontent.com/johankj/61bce11055dafbf475eba0230027fe83/raw/auto-dismiss-data-classification-banner-google-docs.js |
|
// @downloadURL https://gist.githubusercontent.com/johankj/61bce11055dafbf475eba0230027fe83/raw/auto-dismiss-data-classification-banner-google-docs.js |
|
// @description Automatically dismisses the "Data Classification" banner in Google Docs by simulating full mouse events. |
|
// @author Johan |
|
// @match https://docs.google.com/* |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
(function () { |
|
'use strict'; |
|
|
|
// Simulate a full user click via mouse events |
|
function simulateMouseClick(target) { |
|
['mousedown', 'mouseup', 'click'].forEach(type => { |
|
const event = new MouseEvent(type, { |
|
view: window, |
|
bubbles: true, |
|
cancelable: true, |
|
buttons: 1 |
|
}); |
|
target.dispatchEvent(event); |
|
}); |
|
} |
|
|
|
// Check and dismiss the banner if found |
|
function checkAndDismissBanner() { |
|
const banner = document.querySelector('#docs-feature-level-banner'); |
|
if (banner && banner.textContent.includes('Data Classification')) { |
|
//const dismissBtn = banner.querySelector('.docs-odp-banner-dismiss-button'); |
|
const dismissBtn = banner.querySelector('button[aria-label="Close banner"]'); |
|
if (dismissBtn) { |
|
console.log('[Tampermonkey] Found "Data Classification" banner, simulating full click...'); |
|
simulateMouseClick(dismissBtn); |
|
} |
|
} |
|
} |
|
|
|
// Observe mutations to detect when the banner appears |
|
const observer = new MutationObserver(() => { |
|
checkAndDismissBanner(); |
|
}); |
|
|
|
// Wait until the banner container is present, then observe it |
|
function waitForBannerContainer() { |
|
const banner = document.querySelector('#docs-feature-level-banner'); |
|
if (banner) { |
|
observer.observe(banner, { childList: true, subtree: true }); |
|
checkAndDismissBanner(); // Just in case it's already loaded |
|
} else { |
|
setTimeout(waitForBannerContainer, 1000); |
|
} |
|
} |
|
|
|
waitForBannerContainer(); |
|
})(); |