Last active
August 31, 2021 12:31
-
-
Save Maizify/c3aac4a5b6cfe8f2aa45cfcf2bdc3970 to your computer and use it in GitHub Desktop.
保存
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
| var secret = ''; | |
| var dbId = ''; | |
| function getPost() { | |
| var post = {}; | |
| post.url = location.href; | |
| post.author = document.getElementById('js_name').innerText; | |
| post.title = document.getElementById('activity-name').innerText; | |
| post.contentNodes = document.getElementById('js_content').childNodes; | |
| return post; | |
| } | |
| function nodes2Blocks(nodes) { | |
| var blockList = []; | |
| var _handle = (nodes) => { | |
| for (var i = 0; i < nodes.length; i++) { | |
| var node = nodes[i]; | |
| var block = { | |
| object: 'block', type: '', | |
| }; | |
| if (node.nodeName === 'IMG') { | |
| var src = node.dataset.src || node.src || ''; | |
| if (src.startsWith('http')) { | |
| block.type = 'image'; | |
| block.image = { | |
| type: 'external', | |
| external: { | |
| url: src.replace('\/', '/').replace('http:', 'https:'), | |
| }, | |
| }; | |
| } | |
| } else if (node.nodeName === '#text') { | |
| var text = node.textContent.trim(); | |
| if (text !== '') { | |
| block.type = 'paragraph'; | |
| block.paragraph = { | |
| text: [{ | |
| type: 'text', | |
| text: { content: text } | |
| }] | |
| }; | |
| } | |
| } else if (node.nodeName === 'MPVIDEOSNAP') { | |
| continue; | |
| } | |
| if (block.type !== '') { | |
| blockList.push(block); | |
| } | |
| if (node.childNodes && node.childNodes.length > 0) { | |
| _handle(node.childNodes); | |
| } | |
| } | |
| } | |
| _handle(nodes); | |
| return blockList; | |
| } | |
| var post = getPost(); | |
| var blocks = nodes2Blocks(post.contentNodes); | |
| var postData = { | |
| parent: { database_id: dbId }, | |
| properties: { | |
| Name: { | |
| title: [{ | |
| text: { content: post.title }, | |
| }], | |
| }, | |
| URL: { | |
| url: post.url, | |
| }, | |
| Author: { | |
| rich_text: [{ | |
| text: { content: post.author }, | |
| }], | |
| }, | |
| }, | |
| children: blocks, | |
| }; | |
| completion(postData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment