Last active
April 24, 2019 06:31
-
-
Save oxo-yuta/919fbff24c7708d476d722ed46237476 to your computer and use it in GitHub Desktop.
Markdown形式のリンクを作成するChrome拡張機能を作ってみた(メモ) ref: https://qiita.com/spadeloves/items/ff953b8a0c93c0ccf0ab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[表示名](https://hoogehoge.com "title") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"name": "Markdown Link Maker", | |
"version": "1.0", | |
"description": "Copy text the Link text written in Markdown", | |
"icons": { | |
"48": "icon/icon48.png" | |
}, | |
"browser_action": { | |
"default_icon": { | |
"48": "icon/icon48.png" | |
}, | |
"default_title": "Make Markdown Link", | |
"default_popup": "popup.html" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<link rel="stylesheet" href="icon.css"> | |
<link rel="stylesheet" href="style.css"> | |
<script src="js/jquery-3.2.1.min.js"></script> | |
</head> | |
<body> | |
<div style="width: 200px;"> | |
<p style="margin: 0 auto; display: block;text-align: center;"> | |
Markdown Link Copied! | |
</p> | |
</div> | |
</body> | |
<script src="js/main.js" type="text/javascript"></script> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<link rel="stylesheet" href="icon.css"> | |
<link rel="stylesheet" href="style.css"> | |
<script src="js/jquery-3.2.1.min.js"></script> | |
</head> | |
<body> | |
<form id="form"> | |
<div> | |
<input type="text" name="copy_text"> | |
</div> | |
</form> | |
<div> | |
<button id="copy_button">COPY!!</button> | |
</div> | |
</body> | |
<script src="js/main.js" type="text/javascript"></script> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("Hello Extension!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = $(location).attr('search'); | |
var title = $("title").text(); | |
console.log("["+ title + "](" + url + '"' + title + '")'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = $(location).attr('search'); | |
var title = $("title").text(); | |
console.log("["+ title + "](" + url + '"' + title + '")'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"permissions":["clipboardRead","tabs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"permissions":["clipboardRead","tabs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//main | |
chrome.tabs.query({active:true}, function(tab) { | |
chrome.tabs.sendMessage(tab[0].id, {text:''}, function(response) { | |
url = tab[0].url; | |
title = tab[0].title; | |
result = "["+ title + "](" + url + ' "' + title + '")'; | |
execCopy(result); | |
}); | |
}); | |
//copy to clipbored | |
function execCopy(string){ | |
var temp = document.createElement('div'); | |
temp.appendChild(document.createElement('pre')).textContent = string; | |
var s = temp.style; | |
s.position = 'fixed'; | |
s.left = '-100%'; | |
document.body.appendChild(temp); | |
document.getSelection().selectAllChildren(temp); | |
var result = document.execCommand('copy'); | |
document.body.removeChild(temp); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//main | |
chrome.tabs.query({active:true}, function(tab) { | |
chrome.tabs.sendMessage(tab[0].id, {text:''}, function(response) { | |
url = tab[0].url; | |
title = tab[0].title; | |
result = "["+ title + "](" + url + ' "' + title + '")'; | |
execCopy(result); | |
}); | |
}); | |
//copy to clipbored | |
function execCopy(string){ | |
var temp = document.createElement('div'); | |
temp.appendChild(document.createElement('pre')).textContent = string; | |
var s = temp.style; | |
s.position = 'fixed'; | |
s.left = '-100%'; | |
document.body.appendChild(temp); | |
document.getSelection().selectAllChildren(temp); | |
var result = document.execCommand('copy'); | |
document.body.removeChild(temp); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("Hello Extension!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"name": "Markdown Link Maker", | |
"version": "1.0", | |
"description": "Copy text the Link text written in Markdown", | |
"icons": { | |
"48": "icon/icon48.png" | |
}, | |
"browser_action": { | |
"default_icon": { | |
"48": "icon/icon48.png" | |
}, | |
"default_title": "Make Markdown Link", | |
"default_popup": "popup.html" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment