Skip to content

Instantly share code, notes, and snippets.

@odaillyjp
Created November 9, 2013 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odaillyjp/7383071 to your computer and use it in GitHub Desktop.
Save odaillyjp/7383071 to your computer and use it in GitHub Desktop.
http://sandbox.onlinephpfunctions.com/ のテキストボックス内の文字に var_dump を挿入する Chrome の拡張。 全ファイル同じフォルダに突っ込んで、Chrome でアドオンとして読み込んで、テキストボックス内で文字を範囲選択してから右クリックして「var_dump を挿入」を選ぶだけ。
chrome.contextMenus.create({
title: "var_dump を挿入",
contexts: ["selection"],
documentUrlPatterns: ["http://sandbox.onlinephpfunctions.com/"],
onclick: function() {
chrome.tabs.executeScript(null, {file: "content_script.js"});
}
});
(function(){
function getSelectedArea(obj) {
var pos = new Object();
pos.start = obj.selectionStart;
pos.end = obj.selectionEnd;
return pos;
}
function setValueTextBox(function_name, obj_name) {
var target = document.getElementsByName(obj_name)[0];
var pos = getSelectedArea(target);
var textValue = target.value;
var selectedTextValue = textValue.slice(pos.start, pos.end);
var beforeTextValue = textValue.slice(0, pos.start);
var afterTextValue = textValue.slice(pos.end);
target.value = beforeTextValue + function_name + "(" + selectedTextValue + ")" + afterTextValue;
return true;
}
setValueTextBox("var_dump", "code");
})();
{
"manifest_version": 2,
"name" : "add_var_dump",
"version" : "1.0",
"description" : "選択部分を var_dump 関数で囲う機能を追加します。",
"permissions" : ["contextMenus", "tabs", "http://sandbox.onlinephpfunctions.com/"],
"background": {
"scripts" : ["background.js"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment