ToggleGist

Toggle files in GitHub Gist

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey to install this script.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        ToggleGist
// @author      Kuba Niewiarowski
// @description Toggle files in GitHub Gist
// @namespace   [email protected]
// @icon        https://github.com/favicon.ico
// @encoding    utf-8
// @include     /^https?:\/\/gist.github.com\/[\w-]+\/.*/
// @require     https://code.jquery.com/jquery-2.1.3.min.js
// @require     https://update.greatest.deepsurf.us/scripts/28721/1108163/mutations.js
// @version     1.1
// ==/UserScript==

jQuery(function($) {
	function addBtn(){
		$('.file-box').each(function() {
			$('<a>', {
				class: 'Button--secondary Button--small Button git-toggle-file',
				href:  '#',
				text:  'Toggle'
			}).click((e) => {
				e.preventDefault();
				$wrapper = $(e.target).parents('.file').find('.blob-wrapper, .blob').first();
				$wrapper.prop('hidden', !$wrapper.prop('hidden'));
			}).appendTo($(this).find('.file-actions .Button').parent());
		});
	}

	document.addEventListener("ghmo:container", addBtn);

	addBtn();

});