Created
February 23, 2024 12:21
-
-
Save taktamur/0811877ad19ec3e78b6db51b381975d3 to your computer and use it in GitHub Desktop.
日記をつけてるScrapboxに日記ボタンを貼り付けるUserScript
This file contains 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
(function() { | |
// ボタンのスタイル | |
const buttonStyle = { | |
position: 'fixed', | |
bottom: '20px', | |
right: '10px', | |
width: '50px', | |
height: '50px', | |
backgroundColor: '#000000', | |
'border-radius': '50%', | |
color: 'black', | |
fontSize: '16px', | |
cursor: 'pointer', | |
}; | |
// ボタン要素を作成 | |
const button = document.createElement('button'); | |
button.textContent = '日記'; | |
button.style.cssText = Object.keys(buttonStyle).map(key => `${key}: ${buttonStyle[key]}`).join(';'); | |
// ボタンクリック時の処理 | |
button.addEventListener('click', () => { | |
console.log("hogehoge"); | |
const date = new Date(); | |
const yyyy = date.getFullYear(); | |
const mm = date.getMonth() + 1; // 月は0始まりなので1を足す | |
const dd = date.getDate(); | |
const formattedDate = `${yyyy}/${mm.toString().padStart(2, '0')}/${dd.toString().padStart(2, '0')}`; | |
location.href = `https://scrapbox.io/taktamur/${formattedDate}`; | |
}); | |
// ボタンをbody要素に追加 | |
document.body.appendChild(button); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment