Greasy Fork

Greasy Fork is available in English.

Copy google translation result to camel case and copy it to clipboard

google翻訳結果をキャメルケースに変換してクリップボードにコピー

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name Copy google translation result to camel case and copy it to clipboard
// @description google翻訳結果をキャメルケースに変換してクリップボードにコピー
// @version  2.01
// @grant    none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js
// @include https://translate.google.co.jp/*
// @namespace http://greasyfork.icu/users/184902
// ==/UserScript==

(function ($) {
  
  var active = true;

	var $btnDiv = $("<div>");
  var $translationResult = $('#result_box');
  
  $btnDiv.css("background-color",active ? "lightgreen":"transparent").
				  css("width","14px").
  				css("height","14px").
  				css("margin","4px").
  				css("border","dotted 2px gray").
  				css("border-radius","10px").
  				css("float","left");
  
  $("#gt-res-tools-l").append($btnDiv); 
 

	$btnDiv.click(function(){
    active = !active;
    $btnDiv.css("background-color", active ? "lightblue":"transparent");
  })
  
    var getResult = function(){
      	  return toCamelcase($translationResult.text())
  }
 
  var setClipboard = function(str){

    var ta = document.createElement("textarea")
    ta.value = str
    document.body.appendChild(ta)
    ta.select()
    document.execCommand("copy")
    ta.parentElement.removeChild(ta)
    
    $btnDiv.css("background-color","lightgreen")

}

var toCamelcase = function(str) {
    if (!str) return str;
     var strs = str.split(/ /),
     len = strs.length;
     if (len <= 1) return str;

     str = strs[0].toLowerCase();
 
    for (var i = 1; i < len; i++) {
        str += strs[i].toLowerCase().replace(/^[a-z]/, function(value) {
            return value.toUpperCase();
        });
    }
 
    return str
};
  
 	const target = document.getElementById("result_box");
	const observer = new MutationObserver((mutations) => {
    if(active)setClipboard(getResult());
  });
  const config = { attributes: true, childList: true, characterData: true };
	observer.observe(target, config);
  
})(jQuery);