Skip to content

Commit 2bbcb32

Browse files
committed
1.0.4
1 parent c66bb49 commit 2bbcb32

13 files changed

+248
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/web-ext-artifacts/*.zip

.htaccess

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SetOutputFilter DEFLATE
2+
AddOutputFilterByType DEFLATE "application/atom+xml" "application/javascript" "application/json" "application/ld+json" "application/manifest+json" "application/rdf+xml" "application/rss+xml" "application/schema+json" "application/vnd.geo+json" "application/vnd.ms-fontobject" "application/x-font-ttf" "application/x-javascript" "application/x-web-app-manifest+json" "application/xhtml+xml" "application/xml" "font/eot" "font/opentype" "image/bmp" "image/svg+xml" "image/vnd.microsoft.icon" "image/x-icon" "text/cache-manifest" "text/css" "text/html" "text/javascript" "text/plain" "text/vcard" "text/vnd.rim.location.xloc" "text/vtt" "text/x-component" "text/x-cross-domain-policy" "text/xml"
3+
4+
# SECTION BEGIN GIT PROTECTION
5+
RedirectMatch 404 /\.git
6+
# SECTION END GIT PROTECTION

.user.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
; Compress file output: https://faq.infomaniak.com/2013
2+
zlib.output_compression = On

content_scripts/opengraph-preview.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
(function() {
2+
/**
3+
* Check and set a global guard variable.
4+
* If this content script is injected into the same page again,
5+
* it will do nothing next time.
6+
*/
7+
if (window.hasRun) {
8+
return;
9+
}
10+
window.hasRun = true;
11+
12+
browser.runtime.onMessage.addListener((message) => {
13+
if(message.command === "getog") {
14+
var document_og_title_el = document.querySelector("meta[property='og:title']");
15+
var document_og_title = "";
16+
if(document_og_title_el) {
17+
document_og_title = document_og_title_el.getAttribute('content');
18+
}
19+
20+
var document_og_image_el = document.querySelector("meta[property='og:image']");
21+
var document_og_image = "";
22+
if(document_og_image_el) {
23+
document_og_image = document_og_image_el.getAttribute('content');
24+
}
25+
26+
var document_og_description_el = document.querySelector("meta[property='og:description']");
27+
var document_og_description = "";
28+
if(document_og_description_el) {
29+
document_og_description = document_og_description_el.getAttribute('content');
30+
}
31+
32+
var document_og_url_el = document.querySelector("meta[property='og:url']");
33+
var document_og_url = "";
34+
if(document_og_url_el) {
35+
document_og_url = document_og_url_el.getAttribute('content');
36+
}
37+
38+
var document_og_type_el = document.querySelector("meta[property='og:type']");
39+
var document_og_type = "";
40+
if(document_og_type_el) {
41+
document_og_type = document_og_type_el.getAttribute('content');
42+
}
43+
44+
var sending = browser.runtime.sendMessage({
45+
og_title: document_og_title,
46+
og_image: document_og_image,
47+
og_description: document_og_description,
48+
og_url: document_og_url,
49+
og_type: document_og_type,
50+
});
51+
}
52+
});
53+
})();

icons/og-48.png

4.09 KB
Loading

icons/og-96.png

8.55 KB
Loading

icons/og-dark-48.png

3.49 KB
Loading

icons/og-dark-96.png

6.91 KB
Loading

manifest.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Open Graph Preview",
4+
"version": "1.0.4",
5+
"description": "Preview what users will see if this webpage is shared on Facebook. Uses the webpage's OG tags.",
6+
"icons": {
7+
"48": "icons/og-dark-48.png",
8+
"96": "icons/og-dark-96.png"
9+
},
10+
"permissions": [
11+
"activeTab"
12+
],
13+
"browser_action": {
14+
"default_icon": "icons/og-dark-96.png",
15+
"theme_icons": [{
16+
"light": "icons/og-96.png",
17+
"dark": "icons/og-dark-96.png",
18+
"size": 32
19+
}],
20+
"default_title": "Open Graph Preview",
21+
"default_popup": "popup/popup.html"
22+
},
23+
"web_accessible_resources": [
24+
]
25+
}

popup/popup.css

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
html, body {
2+
3+
}
4+
5+
#og-container {
6+
width: 527px;
7+
}
8+
9+
#text-container {
10+
border-left: 1px solid #dadde1;
11+
border-right: 1px solid #dadde1;
12+
border-bottom: 1px solid #dddfe2;
13+
border-right: 1px solid #dddfe2;
14+
margin: 0;
15+
padding: 10px 12px;
16+
background-color: #f2f3f5;
17+
}
18+
19+
#og_url {
20+
color: #606770;
21+
font-size: 12px;
22+
line-height: 16px;
23+
min-height: max-content;
24+
overflow: hidden;
25+
padding: 0;
26+
text-overflow: ellipsis;
27+
text-transform: uppercase;
28+
white-space: nowrap;
29+
font-family: Helvetica, Arial, sans-serif;
30+
}
31+
32+
#og_title {
33+
font-weight: 600;
34+
overflow: hidden;
35+
font-family: inherit;
36+
font-size: 16px;
37+
line-height: 20px;
38+
margin: 5px 0 0;
39+
max-height: 110px;
40+
word-wrap: break-word;
41+
font-family: Helvetica, Arial, sans-serif;
42+
}
43+
44+
#og_description {
45+
margin-top: 3px;
46+
color: #606770;
47+
font-size: 14px;
48+
line-height: 20px;
49+
word-break: break-word;
50+
font-family: Helvetica, Arial, sans-serif;
51+
}
52+
53+
#img-container {
54+
border-left: 1px solid #dadde1;
55+
border-right: 1px solid #dadde1;
56+
border-top: 1px solid #dadde1;
57+
line-height: 0;
58+
}
59+
60+
#info {
61+
font-family: Helvetica, Arial, sans-serif;
62+
}
63+
64+
.cover {
65+
object-fit: cover;
66+
}

popup/popup.html

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
<head>
5+
<meta charset="utf-8">
6+
<link rel="stylesheet" href="popup.css"/>
7+
</head>
8+
9+
<body>
10+
<div id="og-container">
11+
<div>
12+
<div>
13+
<span>
14+
<div id="img-container">
15+
<div>
16+
<div>
17+
<img id="og_image" class="cover" src="preview-image.jpg" width="100%" height="274">
18+
</div>
19+
</div>
20+
</div>
21+
<div id="text-container">
22+
<div>
23+
<div>
24+
<div>
25+
<div id="og_url"></div>
26+
<div></div>
27+
</div>
28+
</div>
29+
<div>
30+
<div>
31+
<h1 id="og_title">Looking for the og:title tag</h1>
32+
</div>
33+
<div id="og_description">Looking for the og:description tag</div>
34+
</div>
35+
</div>
36+
</div>
37+
</span>
38+
</div>
39+
</div>
40+
</div>
41+
42+
43+
<script src="popup.js"></script>
44+
</body>
45+
46+
</html>

popup/popup.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
function handleMessage(request, sender, sendResponse) {
2+
if(request.og_image !== "") {
3+
document.getElementById("og_image").src = request.og_image;
4+
}
5+
if(request.og_title !== "") {
6+
document.getElementById("og_title").textContent = request.og_title;
7+
} else {
8+
document.getElementById("og_title").textContent = "Could not retrieve the og:title tag";
9+
}
10+
11+
if(request.og_description !== "") {
12+
document.getElementById("og_description").textContent = request.og_description;
13+
} else {
14+
document.getElementById("og_description").textContent = "Could not retrieve the og:description tag";
15+
}
16+
17+
document.getElementById("og_url").textContent = request.og_url;
18+
document.getElementById("og_type").textContent = request.og_type;
19+
}
20+
21+
browser.runtime.onMessage.addListener(handleMessage);
22+
23+
function reportExecuteScriptError(error) {
24+
console.error(`Failed to retrieve the Open Graph information : ${error.message}`);
25+
}
26+
27+
/**
28+
* When the popup loads, inject a content script into the active tab,
29+
* and add retrieve the OG tags.
30+
* If we couldn't inject the script, handle the error.
31+
*/
32+
browser.tabs.executeScript({file: "/content_scripts/opengraph-preview.js"})
33+
.then(() => {
34+
browser.tabs.query({active: true, currentWindow: true})
35+
.then(getog)
36+
.catch(reportError);
37+
});
38+
39+
40+
function getog(tabs) {
41+
browser.tabs.sendMessage(tabs[0].id, {
42+
command: "getog"
43+
})
44+
.catch(reportExecuteScriptError);
45+
}
46+
47+
function reportError(error) {
48+
console.error(`Could not retrieve og tags: ${error}`);
49+
}

popup/preview-image.jpg

13.6 KB
Loading

0 commit comments

Comments
 (0)