OSChinaJsonCopyer

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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        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');  
	}  
}