File size: 5,792 Bytes
271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e 88c38b3 271613e |
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
import logger from '../lib/logger'
import emitter from '../lib/emitter'
import Url from 'licia/Url'
import now from 'licia/now'
import startWith from 'licia/startWith'
import $ from 'licia/$'
import upperFirst from 'licia/upperFirst'
import loadJs from 'licia/loadJs'
import trim from 'licia/trim'
import LunaModal from 'luna-modal'
import { isErudaEl } from '../lib/util'
import evalCss from '../lib/evalCss'
let style = null
export default [
{
name: 'すべての境界線',
fn() {
if (style) {
evalCss.remove(style)
style = null
return
}
style = evalCss(
'* { outline: 2px dashed #707d8b; outline-offset: -3px; }',
document.head
)
},
desc: 'すべての要素に色の境界線を追加する',
},
{
name: 'ページを更新',
fn() {
const url = new Url()
url.setQuery('timestamp', now())
window.location.replace(url.toString())
},
desc: 'URLにタイムスタンプを追加して更新する',
},
{
name: '検索テキスト',
fn() {
LunaModal.prompt('テキストを入力してください').then((keyword) => {
if (!keyword || trim(keyword) === '') {
return
}
search(keyword)
})
},
desc: 'ページ上の指定されたテキストを強調表示します',
},
{
name: 'ページの編集',
fn() {
const body = document.body
body.contentEditable = body.contentEditable !== 'true'
},
desc: 'bodyのcontentEditableを切り替える',
},
{
name: '画面に合わせる',
// https://achrafkassioui.com/birdview/
fn() {
const body = document.body
const html = document.documentElement
const $body = $(body)
if ($body.data('scaled')) {
window.scrollTo(0, +$body.data('scaled'))
$body.rmAttr('data-scaled')
$body.css('transform', 'none')
} else {
const documentHeight = Math.max(
body.scrollHeight,
body.offsetHeight,
html.clientHeight,
html.scrollHeight,
html.offsetHeight
)
const viewportHeight = Math.max(
document.documentElement.clientHeight,
window.innerHeight || 0
)
const scaleVal = viewportHeight / documentHeight
$body.css('transform', `scale(${scaleVal})`)
$body.data('scaled', window.scrollY)
window.scrollTo(0, documentHeight / 2 - viewportHeight / 2)
}
},
desc: 'ページ全体を画面に合わせて縮小します',
},
{
name: 'Vueプラグインを読み込む',
fn() {
loadPlugin('vue')
},
desc: 'Vue 開発ツール',
},
{
name: 'Monitorプラグインを読み込む',
fn() {
loadPlugin('monitor')
},
desc: 'ページのfps、メモリ、DOMノードを表示する',
},
{
name: 'Featuresプラグインを読み込む',
fn() {
loadPlugin('features')
},
desc: 'ブラウザ機能の検出',
},
{
name: 'Timingプラグインを読み込む',
fn() {
loadPlugin('timing')
},
desc: 'パフォーマンスとリソースのタイミングを表示する',
},
{
name: 'Codeプラグインを読み込む',
fn() {
loadPlugin('code')
},
desc: 'JavaScript を編集して実行する',
},
{
name: 'Benchmarkプラグインを読み込む',
fn() {
loadPlugin('benchmark')
},
desc: 'JavaScriptベンチマークを実行する',
},
{
name: 'Geolocationプラグインを読み込む',
fn() {
loadPlugin('geolocation')
},
desc: '地理位置情報をテストする',
},
{
name: 'Orientationプラグインを読み込む',
fn() {
loadPlugin('orientation')
},
desc: 'テストオリエンテーション API',
},
{
name: 'Touchesプラグインを読み込む',
fn() {
loadPlugin('touches')
},
desc: '画面タッチを視覚化する',
},
]
evalCss(require('./searchText.scss'), document.head)
function search(text) {
const root = document.body
const regText = new RegExp(text, 'ig')
traverse(root, (node) => {
const $node = $(node)
if (!$node.hasClass('eruda-search-highlight-block')) return
return document.createTextNode($node.text())
})
traverse(root, (node) => {
if (node.nodeType !== 3) return
let val = node.nodeValue
val = val.replace(
regText,
(match) => `<span class="eruda-keyword">${match}</span>`
)
if (val === node.nodeValue) return
const $ret = $(document.createElement('div'))
$ret.html(val)
$ret.addClass('eruda-search-highlight-block')
return $ret.get(0)
})
}
function traverse(root, processor) {
const childNodes = root.childNodes
if (isErudaEl(root)) return
for (let i = 0, len = childNodes.length; i < len; i++) {
const newNode = traverse(childNodes[i], processor)
if (newNode) root.replaceChild(newNode, childNodes[i])
}
return processor(root)
}
function loadPlugin(name) {
const globalName = 'eruda' + upperFirst(name)
if (window[globalName]) return
let protocol = location.protocol
if (!startWith(protocol, 'http')) protocol = 'http:'
loadJs(
`${protocol}//cdn.jsdelivr.net/npm/eruda-${name}@${pluginVersion[name]}`,
(isLoaded) => {
if (!isLoaded || !window[globalName])
return logger.error('Fail to load plugin ' + name)
emitter.emit(emitter.ADD, window[globalName])
emitter.emit(emitter.SHOW, name)
}
)
}
const pluginVersion = {
monitor: '1.1.1',
features: '2.1.0',
timing: '2.0.1',
code: '2.2.0',
benchmark: '2.0.1',
geolocation: '2.1.0',
orientation: '2.1.1',
touches: '2.1.0',
vue: '1.1.1',
}
|