mobile版scrapboxの判定
2021-01-08 18:48もっと簡単な方法があった
code:script.js
export const isMobile = () => /mobile/i.test(navigator.userAgent)
from /shokai/音声入力Menu
/icons/hr.icon
/customize/モバイル版Scrapboxかどうかを判定するUserScriptに載せておいた
/icons/hr.icon
mobile端末かどうかを判定するプログラムをかけるだろうかtakker.icon
css selectorで判定できるか?
mobile版scrapboxにしかないclassを使って判定処理を書いてみる
.drawer-menuを使う
18:34:45 何故かうまく行かないので、別のselectorを使う
undefinedではなくnullが返ってくるみたい
面倒なので配列の数で比較しよう
18:46:08 .touch-scrollable-containerでもだめか……
仕方ないのでremote debug (web)する
19:09:42 なぜかremote debug (web)できない……
deviceをを認識してくれない
19:36:41 FIrefox for Android Nightlyをinstallしてremote debug (web)を開始した
DOMのinspecterがみれない?なぜだ?
19:44:10 .mobile-cursorをみつけた。これを試してみる
/icons/done.icon19:46:05 成功!
.mobile-cursorならうまくいくみたいだな
code:script.js.old(js)
export function isMobile() {
//return ...document.getElementsByClassName('drawer-menu').length > 0;
//return ...document.getElementsByClassName('touch-scrollable-container').length > 0;
//return document.getElementById('page-item-animation').children.length > 0;
//return document.getElementById('drawer-container') !== null;
// for debug
//const temp = ...document.getElementsByClassName('mobile-cursor').length > 0;
//console.log(This is the ${temp ? 'mobile' : 'desktop'} app.);
return ...document.getElementsByClassName('mobile-cursor').length > 0;
}
test用code
code:js
import {isMobile} from '../script.js';
scrapbox.PageMenu.addMenu({
title: 'isMobile',
image: '/assets/img/logo.png'
});
scrapbox.PageMenu('isMobile').addItem({
title: This is a ${isMobile()? 'mobile' : 'desktop'} scrapbox.,
onClick:()=>{},
});
#mobile版scrapbox
#2021-03-28 18:13:50
#2021-01-08
#2020-12-11 22:35:16
#2020-11-12 18:13:28
#2020-10-05 17:21:21
#2020-09-18 07:21:13