Created
September 7, 2017 18:17
-
-
Save HomerJSimpson/aff091e08ccbe81533af3a3fffc160ad to your computer and use it in GitHub Desktop.
Google Chrome Content script to import bookmarks into Google Bookmarks through it's web ui
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
{ | |
"name": "Content Script", | |
"description": "Do you really need a description for that?", | |
"version": "0.2", | |
"manifest_version": 2, | |
"content_scripts": [{ | |
"run_at" : "document_end", | |
"matches": [ "*://*.google.com/bookmarks/mark*", "*://*.google.com/bookmarks/lookup*" ], | |
"js": ["script.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
console.log(`in: ${window.location}`); | |
if(window.location.pathname.indexOf('/mark') >= 0) { | |
const data = JSON.parse(localStorage.getItem('data')); | |
const els = document.querySelectorAll('input#bkmk_n,input#bkmk_u,input#bkmk_label_1,textarea,a[class*="submit"]'); | |
const el = data.find(e => !e.written); | |
el.tags.push('delicious'); | |
const setElements = (e) => (els[0].value = el.title, els[1].value = el.href, els[2].value = el.tags.join(', '), els[3].value = `Added from delicious backup on ${new Date(el.added*1000).toISOString()}`); | |
if(el) { | |
setElements(el); | |
el.written = true; | |
localStorage.setItem('data', JSON.stringify(data)); | |
els[4].click(); | |
} | |
} else { | |
const link = document.querySelector('a[href*="op=add"]'); | |
console.log(link); | |
link.click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment