Last active
October 15, 2022 09:32
-
-
Save bramblex/e3e37aa671fd8c3aa92924405994c135 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name lark-doc-lock | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://bytedance.feishu.cn/* | |
// @require https://github.com/bramblex/MonkeyBox/raw/master/monkey-box.user.js | |
// ==/UserScript== | |
const id = 'lark_doc_lock'; | |
const cache = new $MonkeyBox.utils.Cache(id); | |
const defaultLocked = cache.get('default_locked') | |
let timer = null; | |
function keep(fn, timeout){ | |
clearInterval(timer); | |
fn(); | |
timer = setInterval(fn, timeout); | |
} | |
function toggleLock(locked){ | |
keep(() => { | |
const docBody = document.getElementById('innerdocbody'); | |
if (docBody) { | |
if (locked) { | |
docBody.contenteditable = false; | |
docBody.style.pointerEvents = 'none'; | |
} else { | |
docBody.contenteditable = true; | |
docBody.style.pointerEvents = ''; | |
} | |
} | |
}, 300) | |
} | |
$MonkeyBox | |
.register(id, '锁定 lark 文档', { | |
data: function () { | |
return { | |
defaultLocked: defaultLocked, | |
locked: defaultLocked, | |
}; | |
}, | |
template: `<div> | |
<div @click="toggleLocked">锁定<{{ locked ? '√': '×' }}></div> | |
<div @click="toggleDefaultLocked">默认锁定<{{ defaultLocked ? '√' : '×'}}></div> | |
</div>`, | |
methods: { | |
toggleLocked() { | |
this.locked = !this.locked; | |
toggleLock(this.locked); | |
}, | |
toggleDefaultLocked() { | |
this.defaultLocked = !this.defaultLocked; | |
cache.set('default_locked', this.defaultLocked); | |
} | |
}, | |
created() { | |
toggleLock(this.locked); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment