Youtube Logout Confirm

Prevent logout all your account accidentally by misclick at YouTube.

安装此脚本?
作者推荐脚本

您可能也喜欢Google Logout Confirm

安装此脚本
  1. // ==UserScript==
  2. // @name Youtube Logout Confirm
  3. // @name:zh 防止在 Youtube 誤觸登出
  4. // @namespace http://tampermonkey.net/
  5. // @author Microdust
  6. // @version 1.0
  7. // @description Prevent logout all your account accidentally by misclick at YouTube.
  8. // @description:zh 為 Youtube 登出鈕增加確認對話框,避免誤點導致帳號全部登出
  9. // @include *://*.youtube.com/*
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const MSG = (() => {
  18. const userLanguage = navigator.language || navigator.userLanguage;
  19. switch (userLanguage) {
  20. case 'zh-TW':
  21. return '確定要登出嗎?';
  22. case 'zh-HK':
  23. return '確定要登出嗎?';
  24. case 'zh-CN':
  25. return '确定要登出吗?';
  26. default:
  27. return 'Are you sure you want to log out?';
  28. }
  29. })();
  30.  
  31. function confirmLogout(element) {
  32. const parent = element.closest('a');
  33. if (parent && !parent.dataset.processed) {
  34. parent.dataset.processed = 'true';
  35. const clonedLink = parent.cloneNode(false);
  36. clonedLink.removeAttribute('href');
  37. clonedLink.appendChild(parent.children[0]);
  38. clonedLink.addEventListener('click', (event) => {
  39. event.preventDefault();
  40. if (confirm(MSG)) {
  41. parent.click();
  42. }
  43. });
  44.  
  45. parent.parentElement.insertBefore(clonedLink, parent);
  46. parent.style.display = 'none';
  47. }
  48. }
  49.  
  50. const observer = new MutationObserver((mutationsList) => {
  51. for (const mutation of mutationsList) {
  52. if (mutation.type === 'childList') {
  53. const logoutElements = Array.from(document.querySelectorAll('[id=endpoint]')).filter(el => el.href.includes('logout') && !el.closest('a').dataset.processed);
  54. if (logoutElements.length) {
  55. confirmLogout(logoutElements[0]);
  56. }
  57. }
  58. }
  59. });
  60.  
  61. observer.observe(document.body, { childList: true, subtree: true });
  62. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址