[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
アップロード可能なサイズ(初期設定は 1MB)を超えた場合、以下で画像を圧縮している。
_core/lib/edit.js function imageCompressor
再帰的に圧縮を試み、10回試みて失敗したら諦めている。
圧縮してアップロードするため「config.cgi で $image_maxsize の値を0にしても画像をアップロードできちゃうのかな」と思ったがそんなことはなかった。ここの値を0にすれば問題なくアップロードを禁止できる。
const url = PropertiesService.getScriptProperties().getProperty('EXTERNAL_URL') || 'https://sheeprogramming.iku4.com/';
こうすると環境変数に値が入っていればそれを使うし、入ってなければデフォルト値を使う、というのができる。テスト環境限定の挙動とかしたい場合に使えるかも。
GAS で書いた。
function myFunction() {
const styles = [
{
name: 'getFontSize',
func: (val)=>{if(val) {return `font-size:${val}px;`}}
}, {
name: 'getForegroundColor',
func: (val)=>{if(val) {return `color:${val};`}}
}, {
name: 'isBold',
func: (val)=>{if(val) {return `font-weight:bold;`}}
}, {
name: 'isItalic',
func: (val)=>{if(val) {return 'font-style: italic;';}}
}, {
name: 'isStrikethrough',
func: (val)=>{if(val) {return 'text-decoration: line-through ';} else {return 'text-decoration: ';}}
}, {
name: 'isUnderline',
func: (val)=>{if(val) {return 'underline;';} else {return ';';}}
}
];
const sheet = SpreadsheetApp.getActiveSheet();
const cell = sheet.getRange(1, 1);
const elements = cell.getRichTextValue().getRuns();
const html = elements.map((element)=>{
const style = styles.map((style)=>{
return style.func(element.getTextStyle()[style.name]()) || '';
}).join('');
return `<span style="${style}">${element.getText().replaceAll('\n', '<br/>')}</span>`;
}).join('');
console.log(html);
}
const element = document.getElementById('targetElement');
const targetElementPosition = window.pageYOffset + element.getBoundingClientRect().top;
document.getElementsByTagName('body')[0].onscroll = (e) => {
const pos = window.pageYOffset;
if( targetElementPosition > pos ) {
// 処理
}
};
対象となる要素がページの上端からどれだけの距離にあるのか計算する の応用とかの話
const element = document.getElementById('targetElement');
console.log(window.pageYOffset + element.getBoundingClientRect().top);
window.pageYOffset でスクロールがページの上端からどれくらいの位置にあるのかを取得する。
element.getBoundingClientRect() で今のスクロール位置からの相対距離と要素のサイズを取得する。そのうち、 top の値が今のスクロール位置との相対的な高さとなる。