-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,789 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
built-files/bookmarks.pem | ||
|
||
*.crx | ||
|
||
*.xpi | ||
*.pem |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Preparing everything | ||
Execute `prepare.sh` and you'll have all set | ||
|
||
To update the bookmarks use `sudo sed -i 's@^BOOKMARKS.*"@BOOKMARKS="'"${BOOKMARKS}"'"@' /usr/bin/` | ||
|
||
# Building chromium extension | ||
To build the chromium extension is through the Pack extension option in the Extension options | ||
|
||
# Building firefox extension | ||
To build the firefox extension is enough with compressing the bookmark-bridge folder into an xpi file | ||
``` | ||
cd bookmark-bridge && 7z a ../bookmark-bridge.xpi * -r | ||
``` | ||
|
||
# Notes | ||
This extension requires `python-is-python3` to work properly | ||
|
||
# Relevant paths | ||
FF_NATIVE_HOST="/usr/lib/mozilla/native-messaging-hosts" | ||
FF_EXT_PATH="/usr/lib/firefox-esr/distribution/extensions" | ||
CHROME_NATIVE_HOST="/etc/opt/chrome/native-messaging-hosts" | ||
CHROME_EXT_PATH="/opt/google/chrome/extensions" | ||
CHROMIUM_NATIVE_HOST="/etc/chromium/native-messaging-hosts" | ||
CHROMIUM_EXT_PATH="/usr/share/chromium/extensions" |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import json | ||
import struct | ||
import subprocess | ||
import time | ||
|
||
def get_data(): | ||
result = subprocess.run(['/usr/bin/current-bookmarks'], capture_output=True, text=True).stdout.strip() | ||
return result | ||
|
||
# Encode a message for transmission, | ||
# given its content. | ||
def encodeMessage(messageContent): | ||
# https://docs.python.org/3/library/json.html#basic-usage | ||
# To get the most compact JSON representation, you should specify | ||
# (',', ':') to eliminate whitespace. | ||
# We want the most compact representation because the browser rejects | ||
# messages that exceed 1 MB. | ||
encodedContent = json.dumps(messageContent, separators=(',', ':')).encode('utf-8') | ||
encodedLength = struct.pack('@I', len(encodedContent)) | ||
return {'length': encodedLength, 'content': encodedContent} | ||
|
||
# Send an encoded message to stdout | ||
def sendMessage(encodedMessage): | ||
sys.stdout.buffer.write(encodedMessage['length']) | ||
sys.stdout.buffer.write(encodedMessage['content']) | ||
sys.stdout.buffer.flush() | ||
|
||
while True: | ||
# receivedMessage = getMessage() | ||
# if receivedMessage == "ping": | ||
sendMessage(encodeMessage(get_data())) | ||
time.sleep(60) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
BOOKMARKS="{Codeforces^https://cpciitsur.contest.codeforces.com/}|{Omegaup^https://omegaup.com/}|" | ||
echo "$BOOKMARKS" |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
function isFirefox() { | ||
return navigator.userAgent.indexOf("Firefox") > -1; | ||
} | ||
|
||
let current_browser = isFirefox() ? "firefox" : "chrome"; | ||
|
||
let port = browser.runtime.connectNative("bookmarks_fetcher"); | ||
|
||
function removeTrailingBackslash(bookmark){ | ||
// To avoid issues while comparing URLs, remove the trailing backslash (if exists) | ||
if(bookmark.url[bookmark.url.length - 1] == '/'){ | ||
// Removes the last character | ||
bookmark.url = bookmark.url.slice(0,-1); | ||
} | ||
} | ||
|
||
function parseBookmarkString(bookmarkString) { | ||
let bookmarks = []; | ||
let bookmarkList = bookmarkString.split('|'); | ||
for (let bookmarkStr of bookmarkList) { | ||
if(bookmarkStr.length==0) continue; | ||
let bookmark = bookmarkStr.split('^'); | ||
if (bookmark.length === 2) { | ||
bookmarks.push({ | ||
title: bookmark[0].replace("{", ""), | ||
url: bookmark[1].replace("}", ""), | ||
}); | ||
} | ||
} | ||
return bookmarks; | ||
} | ||
function bookmarkAlreadyExists(directivesBookmark, toolbarBookmarks) { | ||
// On each url remove the trailing dash (URL normalization) | ||
// in case that either the user didn't added a backslash at the end of the url | ||
// or the browser decided that said URL does not require to have a backslash | ||
let directivesBookmarkUrl = directivesBookmark.url.replace(/\/$/, ""); | ||
for (let toolbarBookmark of toolbarBookmarks) { | ||
let toolbarBookmarkUrl = toolbarBookmark.url.replace(/\/$/, ""); | ||
if (directivesBookmarkUrl == toolbarBookmarkUrl) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
async function bookmarksCallback(directivesBookmarksString) { | ||
console.log("Looking for bookmarks"); | ||
let toolbarID = current_browser === "firefox" ? "toolbar_____" : "1"; | ||
let toolbarBookmarks = await browser.bookmarks.getChildren(toolbarID); | ||
let directivesBookmarks = parseBookmarkString(directivesBookmarksString); | ||
directivesBookmarks.forEach(directivesBookmark => { | ||
if (!bookmarkAlreadyExists(directivesBookmark, toolbarBookmarks)) { | ||
console.log("Adding", directivesBookmark.title); | ||
browser.bookmarks.create({ | ||
"parentId": toolbarID, | ||
"title": directivesBookmark.title, | ||
"url": directivesBookmark.url, | ||
}); | ||
} | ||
}); | ||
} | ||
// bookmarksCallback("{Codeforces^https://cpciitsur.contest.codeforces.com/}|{Omegaup^https://omegaup.com/}|"); | ||
/* | ||
Listen for messages from the app. | ||
*/ | ||
port.onMessage.addListener((response) => { | ||
// console.log("Received: " + response); | ||
bookmarksCallback(response); | ||
}); |
Oops, something went wrong.