bookmarks icon indicating copy to clipboard operation
bookmarks copied to clipboard

Recognize Shorten URLs

Open ghost opened this issue 4 years ago • 5 comments

Is your feature request related to a problem? Please describe. For example, I would like to add a YouTube video "Big Buck Bunny" to my bookmarks. https://www.youtube.com/watch?v=YE7VzlLtp-4 However I have stored the same video in shorten URL. https://youtu.be/YE7VzlLtp-4 The bookmarklet may recognize a duplicated URL, however the shorten URL is not recognized.

javascript:(function(){var a=window,b=document,c=encodeURIComponent,e=c(document.title),d=a.open('https://example.com/nextcloud/apps/bookmarks/bookmarklet?url='+c(b.location)+'&title='+e,'bkmk_popup','left='+((a.screenX||a.screenLeft)+10)+',top='+((a.screenY||a.screenTop)+10)+',height=500px,width=550px,resizable=1,alwaysRaised=1');a.setTimeout(function(){d.focus()},300);})();

Describe the solution you'd like

  • Promote if a video URL has been stored in shorten URL in the bookmarklet, and vice versa.
  • Automatically shorten the URL.

Describe alternatives you've considered I would like to know which lines to edit for personal use if the idea sounds not helpful.

ghost avatar Mar 02 '21 16:03 ghost

This is a good idea!

Here's the line that does the find API request https://github.com/nextcloud/bookmarks/blob/master/src/components/ViewBookmarklet.vue#L138

The API request is processed on the server here: https://github.com/nextcloud/bookmarks/blob/master/lib/Db/BookmarkMapper.php#L273 as part of the general findAll method: https://github.com/nextcloud/bookmarks/blob/master/lib/Db/BookmarkMapper.php#L193

It may be best to determine the redirected URL on the client or in a separate API call to not change the behavior of the current API.

marcelklehr avatar Mar 02 '21 17:03 marcelklehr

Let me know if you'd like to work on this and also feel free to comment here or drop by on https://gitter.im/nextcloud-bookmarks/community or https://cloud.nextcloud.com/call/u52jcby9 if you'd like some pointers or discuss this some more :)

marcelklehr avatar Mar 02 '21 17:03 marcelklehr

I simply changed https://github.com/nextcloud/bookmarks/blob/master/src/components/ViewBookmarklet.vue#L81 . -this.url +this.url.replace('https://www.youtube.com/watch?v=', 'https://youtu.be/') Though it meets my need, I don't understand where does this.url come from.

https://github.com/nextcloud/bookmarks/blob/master/src/components/ViewBookmarklet.vue#L138 And I don't know how the API works. Changing the statements inside async findBookmark(url) doesn't work. -const bookmark = await this.$store.dispatch(actions.FIND_BOOKMARK, url) +const bookmark = await this.$store.dispatch(actions.FIND_BOOKMARK, url.replace('https://www.youtube.com/watch?v=', 'https://youtu.be/')) I am no developer so I am afraid that I cannot help with it...

ghost avatar Mar 03 '21 20:03 ghost

The URL comes from the router: https://github.com/nextcloud/bookmarks/blob/master/src/router.js#L90

Changing the statements inside async findBookmark(url) doesn't work.

That's likely because you need to rebuild the app after changing the code.

I am no developer so I am afraid that I cannot help with it...

Ah, that's unfortunate. Nobody is a developer until they try it, though ;)

marcelklehr avatar Mar 04 '21 11:03 marcelklehr

Okay I figured out something tricky. I didn't press Ctrl + Shift + R, so the bookmarklet that I actually got was cache. Now it works well for my personal use, but I cannot make it pretty when there is a list of shorten URL rules. Thank you for helping. ViewBookmarklet.vue:

...
                async findShortenUrlBookmark(url) {
                        let shortenUrl = url.replace('https://www.youtube.com/watch?v=', 'https://youtu.be/')
                        shortenUrl = shortenUrl.replace('https://www.nicovideo.jp/watch/', 'https://nico.ms/')
                        const shortenUrlBookmark = await this.$store.dispatch(actions.FIND_BOOKMARK, shortenUrl)
                        if (shortenUrlBookmark) {
                                this.exists = true
                                this.bookmark = shortenUrlBookmark
                                if (this.bookmark.folders.length) {
                                        this.folder = this.bookmark.folders[0]
                                }
                        } else {
                                this.bookmark.url = shortenUrl
                        }
                },
...

ghost avatar Mar 04 '21 20:03 ghost