Clears cookies and other website data when you go to websites if it isn't allowed to store website data. Edit the code to include websites that can store data.
当前为
// ==UserScript==
// @name Cookie and website data cleaner
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Clears cookies and other website data when you go to websites if it isn't allowed to store website data. Edit the code to include websites that can store data.
// @author https://greasyfork.org/en/users/85040-dan-wl-danwl
// @license MIT
// @match *://*/*
// @run-at document-start
// @grant none
// ==/UserScript==
// MIT License
// Copyright(c) 2024 DanWL
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
(function() {
// clearing website storage may prevent certain features from working correctly
// such as remembering which websites you are logged into, which items are in your basket when shopping etc.
// start config
var clearWebsiteDataEveryXMilliseconds = 200;// any number
var websitesToNotRunOn = {
// enter in format 'https://example.com': true,
};
// end config
// runs on websites unless listed in websitesToNotRunOn
if (websitesToNotRunOn[location.origin]) {
return;
}
function joinArray(array, seperator, start, end) {
var joined = '';
for (var i = start; i < end; i++) {
joined += array[i] + seperator;
}
return joined;
}
function clearCookie(cookieName, domain, path) {
// https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
// https://stackoverflow.com/questions/5688491/unable-to-delete-cookie-from-javascript
// can only delete cookie if same domain and path are used as what's already been set
var pathParts = location.pathname.split(/\//g);
[location.hostname, location.host].forEach(function(domain) {
while (domain) {
for (var i = 0; i < pathParts.length; i++) {
var path = joinArray(pathParts, '/', 0, i);
document.cookie = cookieName + '=;' + ' expires=' + new Date(0).toUTCString() + ';' + ' max-age=0;' + ' domain=' + domain + ';' + ' path=' + path + ';';
}
domain = domain.replace(/^\.?[^.]+/, '');
}
});
}
function clearCookies() {
var cookieRe = /([^=]+)=[^;]+(?:;\s+|$)/;
document.cookie.match(new RegExp(cookieRe, 'g') || []).forEach(function(cookie) {
var cookieName = cookie.match(cookieRe)[1];
clearCookie(cookieName);
});
}
function resetWebsiteData() {
try {
clearCookies();
['localStorage', 'sessionStorage'].forEach(function(storage) {
window[storage].clear();
});
}
catch (err) {
// page may not have loaded yet or browser doesnt support localStorage or sessionStorage
}
}
setInterval(resetWebsiteData, clearWebsiteDataEveryXMilliseconds);
resetWebsiteData();
})();