Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bramblex
Last active October 15, 2022 09:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bramblex/e3e37aa671fd8c3aa92924405994c135 to your computer and use it in GitHub Desktop.
Save bramblex/e3e37aa671fd8c3aa92924405994c135 to your computer and use it in GitHub Desktop.
// ==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