Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing a list of URLs as bookmarks #2

Closed
Immortalin opened this issue Sep 10, 2018 · 2 comments
Closed

Importing a list of URLs as bookmarks #2

Immortalin opened this issue Sep 10, 2018 · 2 comments

Comments

@Immortalin
Copy link

Immortalin commented Sep 10, 2018

This builds upon your method of importing tabs and allows the tabs to be imported as bookmarks.
Not the cleanest code but works.

This can only be done manually and imported through chrome's import bookmarks in HTML API due to rate limiting.

https://stackoverflow.com/questions/19374378/how-to-import-bookmarks-programmatically

tabs = document.querySelector("#-blink-dev-tools > div.widget.vbox.root-view > div > div > div > div:nth-child(1) > div > div").shadowRoot.querySelector("div > div.hbox.devices-container > div.flex-auto.vbox > div > div.device-browser-list.vbox > div > div.device-page-list.vbox.device-view-more-toggled").querySelectorAll("div.vbox")



str = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
     It will be read and overwritten.
     DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
    <DT><H3 ADD_DATE="1536609418" LAST_MODIFIED="1536609442" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks bar</H3>
    <DL><p>`;
for (i=0;i<tabs.length;i++){
  if (tabs[i] != null){
    str += ' <DT><A HREF="' + tabs[i].querySelector('div.device-page-url > x-link').attributes.href.value +' "ADD_DATE="1536609434">'+ tabs[i].querySelector('.device-page-title').textContent + '</A>' +'\n'
  } else {
    console.log(tabs[i])
  }
}

str+=    `</DL><p>
</DL><p>`;
copy(str)

Some URLS may have the chrome-distiller prefix. These have to be resolved manually as they are web pages that were in Reader's mode when imported as tabs. Please feel free to clean up the code, add this to the wiki or spin into a browser extension etc.

@Immortalin
Copy link
Author

Script updated to fix Chrome Shadow DOM shenanigans. Fixes #3

@Immortalin
Copy link
Author

Immortalin commented Jul 15, 2019

Script updated again for latest Chrome version. @lmmx, #3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant