Skip to content
This repository has been archived by the owner on Nov 26, 2018. It is now read-only.

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zegnat committed Sep 21, 2016
0 parents commit cb21b4a
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.svg
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Martijn van der Ven

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This WebExtension is based on an idea for distributed profile verification by
Kevin Marks. His implementation uses the great IndieWebify.Me, while this
version keeps everything contained to the user’s browser.
→ https://github.com/indieweb/verify-me

The current application icon(s) are from the Firefox OS Emojis project and used
under Creative Commons Attribution 4.0 International (CC BY 4.0).
→ https://github.com/mozilla/fxemoji

The verification icons are by Kevin Marks, who has given permission for their
inclusion in this extension.
→ http://www.kevinmarks.com/
73 changes: 73 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
chrome.runtime.onMessage.addListener(function (data, sender, respond) {
// If we are checking two URLs against eachother, assume they also link to eachother.
if (data.from === data.to) {
respond({status: 'verified', index: data.index})
return false
}

// Fetch the external page.
window.fetch(data.from).then(function (response) {
if (response.ok) {
response.text().then(function (contents) {
let responded = false
let parser = new window.DOMParser()
let page = parser.parseFromString(contents, 'text/html')
let relMeLinks = page.querySelectorAll('a[rel~="me"][href^="http"]')
// Walk through all found rel-me links to see if any of them matches.
// Build a collection of all URLs so we can fetch those later if neccessary.
let urls = []
for (let i = 0, size = relMeLinks.length; i < size; i++) {
if (relMeLinks[i].href === data.to) {
respond({status: 'verified', index: data.index})
responded = true
break
}
urls.push(relMeLinks[i].href)
}
// If we have not sent a response yet, we did not find a direct link back.
// Parse all the URLs to see if any of them resolve through redirect.
if (!responded) {
if (urls.length > 0) {
fetchNext(urls, respond, data)
} else {
respond({status: 'unverified', index: data.index})
}
}
})
} else {
// The response had a not-OK HTTP status.
respond({status: 'unverified', index: data.index})
}
}).catch(function () {
// Fetch was rejected, probably a network error of some kind.
respond({status: 'unverified', index: data.index})
})

// Return true so the browser will keep waiting for an asynchronous response.
return true
})

function fetchNext (urls, respond, data) {
if (urls.length === 0) {
respond({status: 'unverified', index: data.index})
} else {
let url = urls.shift()
window.fetch(url, {
method: 'HEAD',
headers: new Headers({ 'User-Agent': '' })
}).then(function (response) {
if (response.url === data.to) {
respond({status: 'verified', index: data.index})
} else {
fetchNext(urls, respond, data)
}
}).catch(function (err) {
// Fetch was rejected, probably a network error of some kind?
fetchNext(urls, respond, data)
})
}
}

chrome.browserAction.onClicked.addListener(function () {
chrome.tabs.executeScript(null, {file: 'content_script.js'})
})
16 changes: 16 additions & 0 deletions src/content_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(function (window, document) {
let canonicalUrl = document.querySelector('link[rel~="canonical"]')
let url = (canonicalUrl ? canonicalUrl.href : window.location.href).split('#')[0]
let relMeLinks = document.querySelectorAll('a[rel~="me"][href^="http"]')
for (let i = 0, links = relMeLinks.length; i < links; i++) {
chrome.runtime.sendMessage({from: relMeLinks[i].href, to: url, index: i}, function (response) {
let element = relMeLinks[response.index]
element.classList.add(response.status)
if (response.status === 'verified') {
element.insertAdjacentHTML('afterend', '<svg xmlns="http://www.w3.org/2000/svg" width="1em" style="vertical-align:text-bottom" viewbox="0 0 40 40"><circle cx="20" cy="20" r="18" fill="green" stroke="lightgreen" stroke-width="3"/><path d="M 10,20 18,28 33,14" fill="none" stroke="white" stroke-width="6"/></svg>')
} else if (response.status === 'unverified') {
element.insertAdjacentHTML('afterend', '<svg xmlns="http://www.w3.org/2000/svg" width="1em" style="vertical-align:text-bottom" viewbox="0 0 40 40"><circle cx="20" cy="20" r="18" fill="darkred" stroke="red" stroke-width="3"/><path d="M 10,10 30,30 M 10,30 30,10" fill="none" stroke="white" stroke-width="6"/></svg>')
}
})
}
}(window, document))
Binary file added src/icons/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/icon-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/icon-19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/icon-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/icon-38.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/icon-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/icon-64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"manifest_version": 2,
"name": "rel-me check",
"version": "0.1.0",
"description": "Add a button to the browser UI allowing you to check rel-me links on any page.",
"icons": {
"16": "icons/icon-16.png",
"32": "icons/icon-32.png",
"48": "icons/icon-48.png",
"128": "icons/icon-128.png"
},
"browser_action": {
"default_title": "Check rel-me links on this page.",
"default_icon": {
"19": "icons/icon-19.png",
"38": "icons/icon-38.png"
}
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"http://*/",
"https://*/"
]
}

0 comments on commit cb21b4a

Please sign in to comment.