Copyright表示の年号部分をアクセスした年に応じて調整してくれるだけのWeb Components
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
class CopyrightLinkElement extends HTMLElement { | |
static get observedAttributes() { | |
return ['established']; | |
} | |
constructor() { | |
super(); | |
} | |
connectedCallback() { | |
} | |
attributeChangedCallback(name, oldValue, newValue) { | |
var established = newValue; | |
if (established == null || established == "" || /[^\d]/.test(established)) { | |
established = 2020; | |
} | |
var now = new Date(); | |
var year = now.getFullYear(); | |
var yearspan = ""; | |
if (year <= established) { | |
yearspan = year; | |
} else { | |
yearspan = established+"-"+year; | |
} | |
this.innerHTML = 'Copyright '+yearspan+' by <a href="https://pandanote.info/">pandanote.info</a>'; | |
} | |
} | |
customElements.define("pandanote-copyright",CopyrightLinkElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment