tag-youre-it/content_script.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

$(document).ready(function () {
2015-09-26 21:06:24 +02:00
function processSelection () {
var focused = document.activeElement;
var selectedText;
if (focused) {
try {
selectedText = focused.value.substring(
focused.selectionStart, focused.selectionEnd);
2015-09-26 21:06:24 +02:00
} catch (err) {
}
}
if (selectedText == undefined) {
var sel = window.getSelection();
var selectedText = sel.toString();
}
if (selectedText) {
console.log(selectedText);
2015-09-26 21:42:56 +02:00
}
}
2015-09-26 21:06:24 +02:00
document.addEventListener('click', function(evt) {
if (!document.hasFocus()) {
return true;
}
processSelection();
// evt.stopPropagation();
// evt.preventDefault();
}, false);
/*
Take the existing content, make it narrower and
insert a menu for tagging up content.
*/
var isMenuShown = false;
function addMenu () {
if (isMenuShown) return;
$.get('example1.menu.html', function (htmlData) {
$('body').children().wrapAll('<div class="tagit-body" />');
$('.tagit-body').before(htmlData);
$('#js-hide-menu').click(removeMenu);
isMenuShown = true;
});
}
function removeMenu () {
if (!isMenuShown) return;
$('.tagit-body').children().unwrap();
$('.tagit-menu').remove();
isMenuShown = false;
}
$('#js-show-menu').click(addMenu);
2015-09-26 20:48:26 +02:00
});