OSChinaJsonCopyer

OSChina在线JSON代码格式化工具 添加 一键复制

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        OSChinaJsonCopyer
// @author      rjw
// @description OSChina在线JSON代码格式化工具 添加 一键复制
// @namespace   com.uestc.rjw
// @icon        https://raw.githubusercontent.com/babyrjw/StaticFiles/master/logo_oschina.gif
// @license     Apache Licence V2
// @encoding    utf-8
// @date        18/10/2015
// @modified    18/10/2015
// @include     http://tool.oschina.net/codeformat/json
// @require     http://code.jquery.com/jquery-2.1.1.min.js
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_setClipboard
// @grant unsafeWindow
// @run-at      document-end
// @version     1.0.3
// ==/UserScript==


/*
 * === 说明 ===
 *@作者:rjw
 *@Email:[email protected]
 * */

var onekey = $('<input class="btn btn-small btn-primary" id="onkey_copy" type="button" onclick="copy_result()" value="复制">');
$('#format').parent().append(onekey);

unsafeWindow.copy_result = function copy_result(){
	var containerid = 'Canvas';
	if (document.selection) {
		var range = document.body.createTextRange();
		range.moveToElementText(document.getElementById(containerid));
		range.select();
	} else if (window.getSelection) {
		var range = document.createRange();
		range.selectNode(document.getElementById(containerid));
		window.getSelection().removeAllRanges();
		window.getSelection().addRange(range);
	}
	try {  
    // Now that we've selected the anchor text, execute the copy command  
		var successful = document.execCommand('copy');  
		var msg = successful ? 'successful' : 'unsuccessful';  
		alert('Copy  ' + msg);  
	} catch(err) {  
		alert('Oops, unable to copy');  
	}  
}