User:Kuhlau/CopyTitle.js: Difference between revisions

From Honkai: Nexus Anima Wiki
Jump to navigation Jump to search
Kuhlau (talk | contribs)
ugh now i gotta adapt this for vector 2010
 
Kuhlau (talk | contribs)
No edit summary
Line 19: Line 19:
#title-copy-all  {
#title-copy-all  {
    padding: 6px 0;
    padding: 6px 0;
    color: var(--color-progressive);
    color: #0645ad;
    cursor: pointer;
    cursor: pointer;
}
}
Line 25: Line 25:
#title-copy-all:hover {
#title-copy-all:hover {
    text-decoration: underline;
    text-decoration: underline;
    color: var(--color-progressive--hover);
    color: #0645ad;
}
}
`);
`);
Line 36: Line 36:
    class: 'mw-list-item title-copy-button',
    class: 'mw-list-item title-copy-button',
    text: 'Copy title'
    text: 'Copy title'
}).appendTo($('#vector-main-menu #p-navigation .vector-menu-content-list'));
}).appendTo($('#mw-panel #p-navigation .vector-menu-content-list'));


Line 44: Line 44:
    class: 'mw-list-item title-copy-button',
    class: 'mw-list-item title-copy-button',
    text: 'Copy title with namespace'
    text: 'Copy title with namespace'
}).appendTo($('#vector-main-menu #p-navigation .vector-menu-content-list'));
}).appendTo($('#mw-panel #p-navigation .vector-menu-content-list'));


}
}
$('#vector-main-menu .vector-menu-content-list #title-copy-content').click(function() {
$('#mw-panel .vector-menu-content-list #title-copy-content').click(function() {
copy(mw.config.get('wgTitle'), this);
copy(mw.config.get('wgTitle'), this);
});
});


$('#vector-main-menu .vector-menu-content-list #title-copy-all').click(function() {
$('#mw-panel .vector-menu-content-list #title-copy-all').click(function() {
copy(mw.config.get('wgPageName').replace(/_/g, ' '), this);
copy(mw.config.get('wgPageName').replace(/_/g, ' '), this);
});
});

Revision as of 03:29, 14 July 2026

/*
	Appends two buttons to the edit tools to copy the title with/without namespace
	Author: Caburum & Thundercraft5
	Based on code by: RheingoldRiver
	See also: [[w:c:dev:CopyTitle]] (the original script this was from before being modified)
	
	Modified by: Kuhlau
	Kuhlau's notes: This script adds a little button to the side of the page you can use to copy the real title of the current page (not the displayed title).
	Modified further by: Mikevoir (to add lightbox usage and other cleanup)
	Modified even further by: Kuhlau (to add it to vector list)
*/

$(function() {
	if (window.CopyTitleLoaded) {return;}
	window.CopyTitleLoaded = true;
	
	mw.util.addCSS(`
	#title-copy-content ,
	#title-copy-all  {
	    padding: 6px 0;
	    color: #0645ad;
	    cursor: pointer;
	}
	#title-copy-content:hover ,
	#title-copy-all:hover {
	    text-decoration: underline;
	    color: #0645ad;
	}
	`);


	function init() {

		$('<li>', {
		    id: 'title-copy-content',
		    class: 'mw-list-item title-copy-button',
		    text: 'Copy title'
		}).appendTo($('#mw-panel #p-navigation .vector-menu-content-list'));

	
		if (mw.config.get('wgNamespaceNumber') !== 0) {
			$('<li>', {
			    id: 'title-copy-all',
			    class: 'mw-list-item title-copy-button',
			    text: 'Copy title with namespace'
			}).appendTo($('#mw-panel #p-navigation .vector-menu-content-list'));

		}
		$('#mw-panel .vector-menu-content-list #title-copy-content').click(function() {
			copy(mw.config.get('wgTitle'), this);
		});

		$('#mw-panel .vector-menu-content-list #title-copy-all').click(function() {
			copy(mw.config.get('wgPageName').replace(/_/g, ' '), this);
		});
	}

	function copy(text, element) {
		var copyEl = document.createElement('textarea');
		copyEl.value = text;
		document.body.appendChild(copyEl);
		copyEl.select();
		document.execCommand('copy');
		document.body.removeChild(copyEl);
		document.execCommand('copy');

	    var $el = $(element);
	    var originalText = $el.text();

	    $el
	        .addClass('copied')
	        .text('Copied!');

	    setTimeout(function () {
	        $el
	            .removeClass('copied')
	            .text(originalText);
	    }, 1000);
	}
	
	init();
});