Skip to content

Commit

Permalink
v2.5.0 work on Firefox for Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyangs committed Nov 27, 2017
1 parent 9fd46d5 commit 4f8f8ee
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
28 changes: 26 additions & 2 deletions content_scripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,32 @@ let domTextarea = null;
domMenuitem.addEventListener('click', function(){
document.body.appendChild(domTextarea);
domTextarea.select();
document.execCommand('copy');
domTextarea.remove();
let bln = document.execCommand('copy');
if(bln){
domTextarea.remove();
}else{
let scrollX = window.screenX;
let scrollY = window.scrollY;

// https://bugzilla.mozilla.org/show_bug.cgi?id=1420466
let newtext = document.createTextNode('Copying text command was successful. Click to continue.');
let domDiv = document.createElement('div');
domDiv.style.backgroundColor = 'white';
domDiv.style.width = '80%';
domDiv.style.margin = '0 auto';
domDiv.style.padding = 10;
domDiv.appendChild(newtext);
let myLightbox = lightbox({
contentNode: domDiv
});
myLightbox.addEventListener('click', function(){
domTextarea.select();
document.execCommand('copy');
domTextarea.remove();
myLightbox.remove();
window.scroll(scrollX, scrollY);
});
}
});

domMenu.appendChild(domMenuitem);
Expand Down
29 changes: 29 additions & 0 deletions content_scripts/lightbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
let lightbox = function(objOption){
let domDiv = document.createElement('div');
domDiv.setAttribute('style', 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0, 0, 0, .8);');
domDiv.style.display = 'none';
domDiv.addEventListener('click', function(){
domDiv.style.display = 'none';
});
let domTable = document.createElement('table');
let domTr = document.createElement('tr');
let domTd = document.createElement('td');
domTable.setAttribute('style', 'width:100%;height:100%;');
domTd.setAttribute('style', 'vertical-align:middle; text-align:center;');

domTd.appendChild(objOption.contentNode);
domTr.appendChild(domTd);
domTable.appendChild(domTr);
domDiv.appendChild(domTable);
document.body.appendChild(domDiv);
if(objOption.opener){
objOption.opener.addEventListener('click', function(){
domDiv.style.display = 'inline';
});
}else{
domDiv.style.display = 'inline';
}

return domDiv;
};
7 changes: 5 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Fennec Copy Link Text",
"description": "This addon adds a menu item to the context menu, and it lets you easily copy the visible text of the selected link.",
"manifest_version": 2,
"version": "2.0.0",
"version": "2.5.0",
"homepage_url": "https://github.com/shyangs/Fennec-Copy-Link-Text",

"applications": {
Expand All @@ -22,7 +22,10 @@

"content_scripts": [{
"matches": ["<all_urls>", "file:///*"],
"js": ["content_scripts/content.js"],
"js": [
"content_scripts/lightbox.js",
"content_scripts/content.js"
],
"run_at": "document_end",
"all_frames": true
}]
Expand Down

1 comment on commit 4f8f8ee

@protheusdk
Copy link

@protheusdk protheusdk commented on 4f8f8ee Dec 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I'm trying to developt a webextension for firefox, I'm new to this, I would like to know how to generate another item in the context menu. It seems that just one is allowed but I guess it has to be with the id, but I used diferent names. Good work by the way. Thanks for share the code. If you want to check the addon I'm working on is "Textise-it".

Please sign in to comment.