This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
template for sending config info to content scripts
- Loading branch information
Showing
3 changed files
with
57 additions
and
32 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
chrome.runtime.onConnect.addListener((port) => { | ||
port.onMessage.addListener((msg) => { | ||
if (!port.sender || !port.sender.tab || port.sender.id !== chrome.runtime.id) | ||
{ | ||
let ledgerPublisherConfig = {} | ||
|
||
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { | ||
if (!sender.tab || sender.tab.incognito || sender.id !== chrome.runtime.id) | ||
return | ||
|
||
if (msg.type === 'action') { | ||
chrome.ipc.send('dispatch-action', JSON.stringify(msg.action)) | ||
if (msg.type === 'ledger-publisher-config') { | ||
sendResponse(ledgerPublisherConfig) | ||
} | ||
}) | ||
|
||
chrome.ipc.on('background-page-message', (evt, msg) => { | ||
if (msg.type === 'ledger-publisher-update') { | ||
ledgerPublisherConfig = msg.config | ||
} | ||
}) | ||
}) | ||
} |
41 changes: 26 additions & 15 deletions
41
app/extensions/brave/content/scripts/publisherIdentification.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
// // youtube example code | ||
// let publisherInfo = {} | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// // attribution value | ||
// let node = document.querySelector("meta[name='attribution']") | ||
// if (node) { | ||
// publisherInfo.attribution = node.getAttributeNode("content").value | ||
// } | ||
|
||
// // ytid | ||
// node = document.querySelector(".yt-user-info *[data-ytid]") | ||
// if (node) { | ||
// publisherInfo.ytid = node.dataset.ytid | ||
// } | ||
chrome.runtime.sendMessage({type: 'ledger-publisher-config'}, function(ledgerPublisherConfig) { | ||
console.log(ledgerPublisherConfig); | ||
|
||
// if (Object.keys(publisherInfo).length !== 0) { | ||
// ExtensionActions.setPagePublisher(document.location.href, publisherInfo) | ||
// } | ||
let results = {} | ||
|
||
let node = document.head.querySelector("link[rel='icon']") | ||
if (!node) { | ||
node = document.head.querySelector("link[rel='shortcut icon']") | ||
} | ||
if (node) { | ||
results.favicon = node.getAttribute('href') | ||
} | ||
|
||
// hard-coded for now... will be dynamic in the beta (I hope!) | ||
let href = document.location.href | ||
if (href.hostname === 'youtube.com' && href.pathname.indexOf('/channel') === 0) { | ||
node = document.body.querySelector("#watch7-content.watch-main-col meta[itemprop='channelId']") | ||
if (node) results.publisher = node.getAttribute('content') | ||
} | ||
|
||
if (Object.keys(results).length !== 0) { | ||
ExtensionActions.setPageInfo(href, results) | ||
} | ||
}); |
20375fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
20375fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, thanks! I get slack and github usernames mixed up all the time
@mrose17