Skip to content

Instantly share code, notes, and snippets.

@jaydorsey
Last active May 24, 2024 22:17
Show Gist options
  • Save jaydorsey/d1c54ef5fa48668833851423341fbf6f to your computer and use it in GitHub Desktop.
Save jaydorsey/d1c54ef5fa48668833851423341fbf6f to your computer and use it in GitHub Desktop.
Tampermonkey script to sisable the Github automatic list completion behavior
// ==UserScript==
// @name Disable Github List Completion
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Disables the behavior described in https://github.blog/changelog/2020-12-15-markdown-list-syntax-now-autocompleted/
// @author Jay Dorsey
// @match https://*.github.com/*
// @grant window.focus
// ==/UserScript==
(function() {
'use strict';
document.querySelectorAll('.js-task-list-field').forEach(el => { el.classList.remove('js-task-list-field') });
})();
@asmeurer
Copy link

This doesn't always work. Here's an updated script that's more robust (courtesy of ChatGPT):

(function() {
    'use strict';

    function removeAutoComplete() {
        document.querySelectorAll('.js-task-list-field').forEach(el => {
            if (el.classList.contains('js-task-list-field')) {
                el.classList.remove('js-task-list-field');
            }
        });
    }

    // Enhance the observer to check inside newly added nodes more thoroughly
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                // Check if the added node itself needs class removal
                if (node.nodeType === 1 && node.classList && node.classList.contains('js-task-list-field')) {
                    node.classList.remove('js-task-list-field');
                }
                // Also check child elements of the added node
                if (node.nodeType === 1 && node.querySelectorAll) {
                    node.querySelectorAll('.js-task-list-field').forEach(el => {
                        if (el.classList.contains('js-task-list-field')) {
                            el.classList.remove('js-task-list-field');
                        }
                    });
                }
            });
        });
    });

    // Start observing for DOM changes
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // Initial removal on window load
    window.addEventListener('load', removeAutoComplete);
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment