Created
October 15, 2023 04:32
-
-
Save Cyang39/b788282b5d86247575a99744d000de22 to your computer and use it in GitHub Desktop.
Save current page's url in notion
This file contains hidden or 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
javascript:(async function() { | |
const token = "<your token>"; | |
const database = "<your database>"; | |
const url = 'https://corsproxy.io/?https://api.notion.com/v1/pages'; | |
const options = { | |
method: 'POST', | |
headers: { | |
Authorization: `Bearer ${token}`, | |
'content-type': 'application/json', | |
'Notion-Version': '2022-06-28' | |
}, | |
body: `{"parent":{"database_id":"${database}"},"properties":{"Name":{"title":[{"text":{"content":"${document.title}"}}]},"Address":{"url":"${window.location.href}"}}}` | |
}; | |
const messageBox = document.createElement('div'); | |
messageBox.style.position = 'fixed'; | |
messageBox.style.top = '0'; | |
messageBox.style.left = '0'; | |
messageBox.style.width = '100%'; | |
messageBox.style.backgroundColor = 'green'; | |
messageBox.style.color = 'white'; | |
messageBox.style.padding = '10px'; | |
messageBox.style.boxSizing = 'border-box'; | |
messageBox.style.transition = 'opacity 0.3s ease-in-out'; | |
messageBox.style.opacity = '0'; | |
messageBox.style.zIndex = '9999'; | |
document.body.appendChild(messageBox); | |
try { | |
const response = await fetch(url, options); | |
const data = await response.json(); | |
messageBox.innerText = 'Save Success'; | |
messageBox.style.opacity = '1'; | |
setTimeout(() => { | |
messageBox.style.opacity = '0'; | |
}, 3000); | |
console.log(data); | |
} catch (error) { | |
messageBox.innerText = 'Save Fail'; | |
messageBox.style.backgroundColor = 'red'; | |
messageBox.style.opacity = '1'; | |
setTimeout(() => { | |
messageBox.style.opacity = '0'; | |
}, 3000); | |
console.error(error); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment