box-of-js-code
Hub » box-of-js-code


<!--
author: 7happy7
license: CC BY-SA 3.0
-->
<head>
    <style>
body {overflow: hidden;} .table {display: block; font-size: 12px; text-align: center;}#user, #Date1, #Date2 {display: block; width: 0; height: 0; overflow: hidden;}#formIn {width: 100%!important; font-family: verdana, arial, helvetica, 'Meiryo', 'Nanum Gothic', sans-serif;}
#button {display: inline-block; padding: 0.5em 1em; text-decoration: none; background: #f7f7f7; border-left: solid 6px #ff7c5c; color: #ff7c5c; font-weight: bold; box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.29); cursor: pointer; -webkit-appearance:none;}#button:active  {box-shadow: inset 0 0 2px rgba(128, 128, 128, 0.1); transform: translateY(2px);}
@media (max-width: 420px) {#formIn {font-size: 0.85em;}}
    </style>
<head>
<body>
    <div id="page-content">
        <span class="table">
            <textarea id="formIn" rows="3"></textarea><br><br>
            <button id="button">コピー</button>
        </span>
    </div>
 
<script type="text/javascript">
 
//user name -> "Uname"
var UnamePrev = document.location.hash.substr(1);
var Uname = UnamePrev.replace(/%20/g, ' ');
 
//date -> "year", "month", "day"
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
 
//next date -> "nextYear", "nextMonth"
var nextMonthPrev = date.getMonth()+4;
if (nextMonthPrev > 12) {
var nextMonth = nextMonthPrev-8;
var nextYear = year+1;
} else {
var nextMonth = nextMonthPrev;
var nextYear = year;
}
 
//inner HTML (textarea)
formIn = document.getElementById("formIn");
formIn.innerHTML += "||[[*user " + Uname + "]]||[http://www.scp-wiki.net/title Title]||" + year + "-" + month + "-" + day + "||" + nextYear + "-" + nextMonth + "-" + day + "||";
 
//copying textarea
 
//creating div and pre -> "temp"
function execCopy(string) {
var temp = document.createElement('div'); temp.appendChild(document.createElement('pre')).textContent = string;
 
//hiding temp
var elemPosition = temp.style;
elemPosition.position = 'fixed';
elemPosition.left = '-100%';
 
//inserting temp in <body>
document.body.appendChild(temp);
 
//selecting temp
document.getSelection().selectAllChildren(temp);
 
//copying temp and removing it
var result = document.execCommand('copy');
document.body.removeChild(temp);
return result;
}
 
//clicking the button and functioning execCopy(string)
var copySyntax = document.getElementById('formIn');
var button = document.getElementById('button');
button.onclick = function(){
if(execCopy(copySyntax.value)){}
else {alert('コピーに失敗しました。');}};
</script>
</body>