commit bac5d95918d4f8961f4ec9ce8254fc17c2e6dd89 Author: slow-groovin <136044792+slow-groovin@users.noreply.github.com> Date: Mon Dec 9 20:44:36 2024 +0800 commit full code of plugin diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..81f3ec3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# top-most EditorConfig file +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = tab +indent_size = 4 +tab_width = 4 diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..e019f3c --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules/ + +main.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..0807290 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,23 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "env": { "node": true }, + "plugins": [ + "@typescript-eslint" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended" + ], + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], + "@typescript-eslint/ban-ts-comment": "off", + "no-prototype-builtins": "off", + "@typescript-eslint/no-empty-function": "off" + } + } \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..99e663c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Release Obsidian plugin + +on: + push: + tags: + - "*" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: "18.x" + + - name: Build plugin + run: | + npm install + npm run build + + - name: Create release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + tag="${GITHUB_REF#refs/tags/}" + + gh release create "$tag" \ + --title="$tag" \ + --draft \ + main.js manifest.json styles.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f51af6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# vscode +.vscode + +# Intellij +*.iml + +.idea + +# npm +node_modules + +# Don't include the compiled main.js file in the repo. +# They should be uploaded to GitHub releases instead. +main.js + +# Exclude sourcemaps +*.map + +# obsidian +data.json + +# Exclude macOS Finder (System Explorer) View States +.DS_Store diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..b973752 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +tag-version-prefix="" \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7e3be45 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# Sample disguise / 简单伪装 + +## Introduction +Disguise/obscure/hide the content in a very simple way. Prevent your editing content from being seeing clearly too easily by others passing by in public spaces. +![intro.png](intro.png) +## Implementation Principle +This feature is implemented using minimal code. +Modifying the styles of the editing area via CSS. + +## Usage +After installing and activating the plugin: +Click the button in the sidebar to toggle between disguise mode and normal mode. + +## Not Supported: +- Command-based control. +- Defining styles in settings (styles can only be adjusted directly by editing the `styles.css` file in the plugin directory). + +## 功能简介 +一键切换编辑内容的背景颜色和文本颜色, 防止在公共空间中编辑内容时, 被路过的人过于容易的看清楚正在编辑的内容 + +## 实现原理 +使用最简单的方式实现这个功能 +通过css修改编辑框中的样式 + +## 使用方式 +安装并开启插件后, 点击侧边栏中的按钮, 控制伪装/恢复正常 + +## 不支持: +- 命令方式控制 +- 在setting中定义样式(只能直接修改插件目录中的styles.css进行样式调整) diff --git a/esbuild.config.mjs b/esbuild.config.mjs new file mode 100644 index 0000000..a5de8b8 --- /dev/null +++ b/esbuild.config.mjs @@ -0,0 +1,49 @@ +import esbuild from "esbuild"; +import process from "process"; +import builtins from "builtin-modules"; + +const banner = +`/* +THIS IS A GENERATED/BUNDLED FILE BY ESBUILD +if you want to view the source, please visit the github repository of this plugin +*/ +`; + +const prod = (process.argv[2] === "production"); + +const context = await esbuild.context({ + banner: { + js: banner, + }, + entryPoints: ["main.ts"], + bundle: true, + external: [ + "obsidian", + "electron", + "@codemirror/autocomplete", + "@codemirror/collab", + "@codemirror/commands", + "@codemirror/language", + "@codemirror/lint", + "@codemirror/search", + "@codemirror/state", + "@codemirror/view", + "@lezer/common", + "@lezer/highlight", + "@lezer/lr", + ...builtins], + format: "cjs", + target: "es2018", + logLevel: "info", + sourcemap: prod ? false : "inline", + treeShaking: true, + outfile: "main.js", + minify: prod, +}); + +if (prod) { + await context.rebuild(); + process.exit(0); +} else { + await context.watch(); +} diff --git a/intro.png b/intro.png new file mode 100644 index 0000000..e27f4c7 Binary files /dev/null and b/intro.png differ diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..91cd935 --- /dev/null +++ b/main.ts @@ -0,0 +1,51 @@ +import { App, ItemView,WorkspaceTabs,WorkspaceLeaf ,Editor, MarkdownView, MarkdownEditView,Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian'; + + + + + +export default class MyPlugin extends Plugin { + private styleEnabled: boolean = false; + async onload() { + console.log('onload') + + this.addRibbonIcon('eye-off', 'Disguise', () => { + this.toggleStyle() + }); + } + + onunload() { + console.log('onunload') + + } + + + + private toggleStyle() { + this.styleEnabled = !this.styleEnabled; + + if (this.styleEnabled) { + this.applyCustomStyle(); + } else { + this.removeCustomStyle(); + } + } + + private applyCustomStyle() { + const view = this.app.workspace.getActiveViewOfType(ItemView); + const tabContainer=view?.containerEl?.parentElement?.parentElement + + if (tabContainer) { + tabContainer.addClass('content-disguise') + } + } + + private removeCustomStyle() { + const view = this.app.workspace.getActiveViewOfType(ItemView); + const tabContainer=view?.containerEl?.parentElement?.parentElement + + if (tabContainer) { + tabContainer.removeClass('content-disguise') + } + } +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..2529ed7 --- /dev/null +++ b/manifest.json @@ -0,0 +1,9 @@ +{ + "id": "simple-disguise", + "name": "Simple Disguise", + "version": "1.0.0", + "minAppVersion": "0.15.0", + "description": "disguise/obscure/hide the content in a very simple way.", + "author": "slow-groovin", + "isDesktopOnly": false +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..fba46a8 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "simple-disguise", + "version": "1.0.0", + "description": " Obsidian plugin: disguise/obscure/hide the content in a very simple way", + "main": "main.js", + "scripts": { + "dev": "node esbuild.config.mjs", + "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", + "version": "node version-bump.mjs && git add manifest.json versions.json" + }, + "keywords": [], + "author": "", + "license": "MIT", + "devDependencies": { + "@types/node": "^16.11.6", + "@typescript-eslint/eslint-plugin": "5.29.0", + "@typescript-eslint/parser": "5.29.0", + "builtin-modules": "3.3.0", + "esbuild": "0.17.3", + "obsidian": "latest", + "tslib": "2.4.0", + "typescript": "4.7.4" + } +} diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..7bc2233 --- /dev/null +++ b/styles.css @@ -0,0 +1,8 @@ +.content-disguise { + color: rgba(154, 149, 149, 0.66); + --font-text-size: small; +} +.theme-dark .content-disguise { + color: rgba(177, 159, 159, 0.7); + --font-text-size: small; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c44b729 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "inlineSourceMap": true, + "inlineSources": true, + "module": "ESNext", + "target": "ES6", + "allowJs": true, + "noImplicitAny": true, + "moduleResolution": "node", + "importHelpers": true, + "isolatedModules": true, + "strictNullChecks": true, + "lib": [ + "DOM", + "ES5", + "ES6", + "ES7" + ] + }, + "include": [ + "**/*.ts" + ] +} diff --git a/version-bump.mjs b/version-bump.mjs new file mode 100644 index 0000000..d409fa0 --- /dev/null +++ b/version-bump.mjs @@ -0,0 +1,14 @@ +import { readFileSync, writeFileSync } from "fs"; + +const targetVersion = process.env.npm_package_version; + +// read minAppVersion from manifest.json and bump version to target version +let manifest = JSON.parse(readFileSync("manifest.json", "utf8")); +const { minAppVersion } = manifest; +manifest.version = targetVersion; +writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t")); + +// update versions.json with target version and minAppVersion from manifest.json +let versions = JSON.parse(readFileSync("versions.json", "utf8")); +versions[targetVersion] = minAppVersion; +writeFileSync("versions.json", JSON.stringify(versions, null, "\t")); diff --git a/versions.json b/versions.json new file mode 100644 index 0000000..26382a1 --- /dev/null +++ b/versions.json @@ -0,0 +1,3 @@ +{ + "1.0.0": "0.15.0" +}