二次創作同人サイト&てがろぐで使ったjsとcss公開
サーバーを共同で借りてる友人に頼まれたので置いておきます。
全部Oathであるべきところがouthになってます。
使ったり参考にするときは直してください。
TOPページで使っているやつ
見たいカテゴリを選択してクッキーに保存するやつ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| const outh_list = document.querySelectorAll(".outh input[type=checkbox]")
var allCookies = document.cookie; var cookieAge = 60 * 60 * 24 * 365; var is_firstLoad = true;
{ var outhDict = {}; outh_list.forEach(node => { outhDict[node.id] = node; }) if (allCookies != false) { var cookies = cookieGet("outhList"); if (cookies != false) { cookies.forEach(cookie => { var node = outhDict[cookie]; node.click(); })
} } is_firstLoad = false };
function cookieGet(searchKey) { var returnValue = false allCookies.split(";").forEach(cookie => { if (cookie.split("=")[0] == searchKey) { returnValue = cookie.split("=")[1].split(","); } }) return returnValue }
function cookieSet() { var checkCookieList = []; outh_list.forEach(node => { if (node.checked) { checkCookieList.push(node.id); } }); if (checkCookieList.length > 0) { document.cookie = "outhList=" + checkCookieList + ";path=/;domain=ドメイン;max-age=" + cookieAge + ";"; }; };
function allCheck() { if (is_firstLoad == false) { outh_list.forEach(node => { node.click(); });
} }
|
てがろぐで使っているやつ
汎用的なjs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
| const categories = ["dream", "cross_over", "oriuma", "nsfw", "cp", "fanart"]
const authCookie = cookieGet("outhList"); const posts = document.querySelectorAll("div.onelogbox"); const postInput = document.querySelector("textarea.tegalogpost");
{ if (authCookie.length > 0) { firstLoad(); visiblePost(); nsfwImg(); imgToVideo(); if (postInput != null) { postInput.addEventListener('keyup', function () { window.setTimeout(tweetInput, 10) }, false);
} if (isMode("mode-gallery") == false) { postMultiImage(); imageGroup(); setTimeout(function () { const lightbox = GLightbox({ loop: true, plyr: { config: { loop: { active: true }, autoplay: true } } }); }, 100) } } else { window.location.href = "TOPページに戻す" } }
function isMode(mode) { return document.querySelector("body").classList.contains(mode); }
function cookieGet(searchKey) { let returnValue = false; document.cookie.split(";").forEach(cookie => { if (cookie.split("=")[0].trim() == searchKey) { returnValue = cookie.split("=")[1]; returnValue = returnValue.split(","); } }) return returnValue }
function firstLoad() { document.querySelectorAll(".dateseparator").forEach(node => { node.remove(); }) }
function visiblePost() { posts.forEach(post => { const categories = post.querySelectorAll("span.categories a") categories.forEach(cat => { cat.classList.forEach(catClass => { if (catClass.indexOf("cat-") === 0) { let catName = catClass.replace("cat-", ""); if (authCookie.includes(catName) == false) { post.remove(); } }
}) }) if (post.querySelector("a.nsfw")) { if (authCookie.includes("nsfw") == false) { post.remove(); } } }) }
function postMultiImage() { posts.forEach(post => { const onelogBody = post.querySelector(".onelogbody .comment"); let imgLinks = []; for (let i = 0; i < onelogBody.children.length; i++) { let child = onelogBody.children[i]; if (child.classList.length < 1) { if (imgLinks.length > 0) { imageWrap(imgLinks); imgLinks = [] }
} else if (child.classList.contains("imagelink")) { imgLinks.push(child) } else { if (imgLinks.length > 0) { imageWrap(imgLinks); imgLinks = [] } } } if (imgLinks.length > 0) { imageWrap(imgLinks); } }) }
function imageWrap(imgs) { if (imgs.length < 1) { return false } if (imgs.length == 1) { imgs[0].classList.add("one-img") } else if (imgs.length == 2) { imgs.forEach(img => { img.classList.add("two-img") }) } else { imgs.forEach(img => { img.classList.add("multi-img") }) } }
function imageGroup() { for (i = 0; i < posts.length; i++) { let imgs = posts[i].querySelectorAll(".onelogbody .comment a.glightbox"); imgs.forEach(img => { img.dataset.gallery = "gallery_" + String(i); }) } }
function nsfwImg() { posts.forEach(post => { const postCat = post.querySelectorAll("span.categories a"); postCat.forEach(cat => { if (cat.classList.contains("cat-nsfw")) { post.querySelectorAll("a.imagelink").forEach(img => { img.classList.add("nsfw"); }) } if (isMode("onelog")) { document.querySelector('meta[property="og:image"]').setAttribute("content", "NSFW忠告画像のパス") } }) post.querySelectorAll("a.nsfw").forEach(nsfwLink => { let nsfwtxt = document.createElement("span"); nsfwtxt.innerText = "NSFW"; nsfwLink.insertAdjacentHTML("beforeend", "<span>NSFW</span>") }) }) }
let beforeRow = 0;
function tweetInput() { const fontSize = Math.floor(window.getComputedStyle(postInput).getPropertyValue('font-size').replace("px", "")) const rowMaxCharacter = Math.floor(postInput.clientWidth / fontSize) + 1; let rowCount = 0; const rowMatch = new RegExp(".{" + rowMaxCharacter + "}", "g"); postInput.value.split("\n").forEach(txt => { let row = txt.match(rowMatch) if (row != null) { rowCount += row.length + 1 } else { rowCount += 1 } }) rowCount += 1 if (beforeRow != rowCount) { beforeRow = rowCount rowCount = rowCount * 1.2 postInput.style.height = rowCount + "rem" } }
function imgToVideo() { posts.forEach(post => { const imgLinks = post.querySelectorAll("a.imagelink"); imgLinks.forEach(imgLink => { const img = imgLink.querySelector("img"); const src = img.getAttribute("src"); if (src.endsWith(".mp4")) { img.remove(); let container = document.createElement("div"); container.classList.add("video-over"); let playIcon = document.createElement("span"); playIcon.classList.add("material-symbols-outlined") playIcon.innerText = "play_circle"; container.appendChild(playIcon); imgLink.appendChild(container); let video = document.createElement("video"); video.setAttribute("src", src); video.classList.add("embeddedimage"); video.setAttribute("loading", "lazy"); video.loop = true; imgLink.appendChild(video); imgLink.classList.add("video-container"); } }) }) }
|
ギャラリーモードで画像拡大ではなくポストページに飛ばすやつ。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| const galleryPosts = document.querySelectorAll(".onelogmain")
{ imageLinkToPost(); }
function imageLinkToPost() { galleryPosts.forEach(post => { const glightbox = post.querySelector(".glightbox"); const postURL = post.querySelector(".arrowlink").getAttribute("href"); glightbox.setAttribute("href", postURL); glightbox.classList.remove("glightbox") }) }
|
上記のjsに対応した部分だけ抜き出したcss
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
textarea { width: 100%; }
textarea.tegalogpost { height: 100%; min-height: 3rem; line-height: 1.2rem; transition: height 0.05s; }
a.imagelink { display: inline-block; }
a.one-img { width: 100%; max-height: 300px; margin: auto; display: block; }
a.one-img img, a.one-img video { display: block; margin: auto; }
a.two-img, a.multi-img { width: calc(50% - 0.6rem); margin: 0.2rem; }
a.two-img img, a.multi-img img { width: 100%; }
a.multi-img img { aspect-ratio: 4/3; height: auto; margin-bottom: 6px;
}
a.imagelink.nsfw img { display: none; }
a.imagelink.nsfw { background-color: #1F2020; padding: 4rem; border-radius: 5px; border: 3px var(--border-color) solid; }
a.imagelink.nsfw span { display: block; font-size: 2rem; margin: auto; text-align: center; }
|