Skip to content

Instantly share code, notes, and snippets.

@faurehu
Created January 23, 2021 01:34
Show Gist options
  • Save faurehu/66e232e3110412b0c5efbc4b74310bb6 to your computer and use it in GitHub Desktop.
Save faurehu/66e232e3110412b0c5efbc4b74310bb6 to your computer and use it in GitHub Desktop.
Roam Alias Plugin
window.onhashchange = function () {
var isPage = window.location.hash.split('/')[3] == 'page'
if (isPage) {
setTimeout(function () {
var topBlock = document.getElementsByClassName("roam-block")[0].children[0]
var blockValue = topBlock.innerText.split(':')
if (blockValue.length == 2 && blockValue[0] == 'forward') {
var attrs = topBlock.children[1].attributes[1]
if (attrs.name == 'data-link-uid') {
var newUrl = window.location.href.slice(0, -9) + attrs.value
window.location.assign(newUrl)
}
}
}, 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment