Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Some fixes for Obsidian v1.5.3 #5

Open
astreloff opened this issue Jan 7, 2024 · 0 comments
Open

[FIX] Some fixes for Obsidian v1.5.3 #5

astreloff opened this issue Jan 7, 2024 · 0 comments

Comments

@astreloff
Copy link

astreloff commented Jan 7, 2024

Hi! First of all I'm not a developer, I just used ChatGPT to fix issues I encountered since the plugin hasn't been updated in a while and I really like it. I'd be glad if this helps anyone 😄

Fixed issues:

  • The palette for color selection in the Groups section of the "graph" view does not open.
  • Checkboxes in the property panel don't change their state when clicked.

How to fix:

  1. Open file "main.js" in Obsidian plugin folder at \.obsidian\plugins\obsidian-link-opener.
  2. Replace the code starting on line // src/main.ts with provided below and save file.
  3. (Optional) Restart Obsidian, if it was running.
// src/main.ts
var globalLink = "";
var LinkOpenPlugin = class extends import_obsidian4.Plugin {
  async onload() {
    await this.loadSettings();
    this.registerView(LINK_VIEW, (leaf) => new LinkView(this.app.workspace, leaf, ""));
    
    const clickEvt = async (evt) => {
      const el = evt.target;
      if (el.classList.contains("external-link")) {
        const href = el.getAttribute("linkto");
        if (this.settings.openMethod === "modal" && href) {
          new LinkModal(this.app, href, this.settings.modalWidth, this.settings.modalHeight).open();
        } else if (this.settings.openMethod === "browser" && href) {
          window.open(href);
        } else if (this.settings.openMethod === "tab" && href) {
          globalLink = href;
          await this.app.workspace.getLeaf("tab").setViewState({ type: LINK_VIEW, active: true });
          this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(LINK_VIEW)[0]);
          return;
        }
      } else {
        // Вернуть управление по умолчанию для внутренних ссылок
        return;
      }
    };

    // Используйте capture: true, чтобы обработчик события срабатывал раньше других
    this.registerDomEvent(document, "click", clickEvt, true);

    const removeUrl = (evt) => {
      const el = evt.target;
      if (!el.classList.contains("external-link")) {
        return;
      }
      if (el.getAttribute("href") == "javascript:void(0);") {
        return;
      }
      const href = el.getAttribute("href");
      el.setAttribute("linkto", href ? href : "");
      el.setAttribute("href", "javascript:void(0);");
    };
    this.registerDomEvent(document, "mouseover", (evt) => {
      return removeUrl(evt);
    });

    // Ваш код с обработчиком чекбокса
    const updateCheckboxState = () => {
      const checkbox = document.querySelector('.metadata-input-checkbox');
      if (checkbox) {
        this.registerDomEvent(checkbox, 'click', (evt) => {
          evt.stopPropagation();

          // Ваша текущая логика обновления состояния чекбокса
          const currentValue = checkbox.checked;
          checkbox.checked = !currentValue;

          // Дополнительные действия, если необходимо
        });
      }
    };

    // Вызов функции при загрузке панели параметров
    this.register(() => {
      updateCheckboxState();
    });

    this.addSettingTab(new LinkOpenSettingTab(this.app, this));
  }

  onunload() {
    this.app.workspace.detachLeavesOfType(LINK_VIEW);
  }

  async loadSettings() {
    this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
  }

  async saveSettings() {
    await this.saveData(this.settings);
  }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant