Giter Site home page Giter Site logo

Comments (9)

redleafnew avatar redleafnew commented on June 1, 2024

// 删除条目和附件
static async delItemAtt() {
var zoteroPane = Zotero.getActiveZoteroPane();
var items = zoteroPane.getSelectedItems();
// var iaInfo = items.length > 1 ? 'delete-item-and-attachment-mul' : 'delete-item-and-attachment-sig';
// var truthBeTold = ztoolkit.getGlobal("confirm")(getString(iaInfo))
var truthBeTold = ztoolkit.getGlobal("confirm")(getString("delete-item-and-attachment", { args: { count: items.length } }));
if (truthBeTold) {
HelperExampleFactory.delAttDo(items); // 调用仅删除附件的函数
for (let item of items) {
if (item && !item.isNote()) {
item.deleted = true;
await item.saveTx();
}
}
BasicExampleFactory.delItemAttSucess(items); // 附件条目删除成功提示;
}
}

是源代码,你可以再找相应的具体执行的函数,结合 Zotero Action & Tags插件设置快捷键。

from delitemwithatt.

fredericky123 avatar fredericky123 commented on June 1, 2024

感谢,不过我没明白找对应具体的执行函数是怎么找?

我将以下代码设置为script,然后结合action&tags设置快捷键,会报错"unexpected token async"

`// 仅删除附件
static async delAtt() {
var zoteroPane = Zotero.getActiveZoteroPane();

var items = zoteroPane.getSelectedItems();
// var daoInfo = items.length > 1 ? 'delete-attachment-only-mul' : 'delete-attachment-only-sig';
// var truthBeTold = ztoolkit.getGlobal("confirm")(getString(daoInfo));
var truthBeTold = ztoolkit.getGlobal("confirm")(getString("delete-attachment-only", { args: { count: items.length } }));

if (truthBeTold) {
  HelperExampleFactory.delAttDo(items); // 调用仅删除附件的函数
  BasicExampleFactory.delAttSucess(); // 附件删除成功提示;
}

}

// 仅删除附件执行的函数
static async delAttDo(items: Zotero.Item[]) {

for (let item of items) {
  if (item && !item.isNote()) { //2 if
    if (item.isRegularItem()) { // Regular Item 一般条目//3 if
      let attachmentIDs = item.getAttachments();
      for (let id of attachmentIDs) { //4 for
        let attachment = Zotero.Items.get(id);
        let ifLinks = (attachment.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE); // 检测是否为链接模式
        var file = await attachment.getFilePathAsync();
        if (file && ifLinks) { // 如果文件存在(文件可能已经被删除)且为链接模式删除文件
          try {
            // await OS.File.remove(file); // 尝试删除文件
            await Zotero.File.removeIfExists(file);
            //await trash.remove(file);
          } catch (error) { // 弹出错误
            alert(getString("file-is-open"));
            return; // 弹出错误后终止执行
          }
        }
        // if (attachment.attachmentContentType == 'text/html' ) { // 可以筛选删除的附件类型
        attachment.deleted = true; // 删除附件(快照)
        await attachment.saveTx();
        // }

      } //4 for
    } // 3 if
    if (item.isAttachment()) { //附件条目 5 if
      var ifLinksAtt = (item.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE); //检测是否为链接模式
      var file = await item.getFilePathAsync();
      if (file && ifLinksAtt) { // 如果文件存在(文件可能已经被删除)且为链接模式删除文件
        try {
          // await OS.File.remove(file); // 尝试删除文件
          await Zotero.File.removeIfExists(file);
        } catch (error) { // 弹出错误
          alert(getString("file-is-open"));
          return; // 弹出错误后终止执行
        }
      }
      item.deleted = true;
      await item.saveTx();
    }//5if
  } //2 if

}

}`

from delitemwithatt.

redleafnew avatar redleafnew commented on June 1, 2024

可以搜索函数名delAttDo
(https://github.com/redleafnew/delitemwithatt/blob/2ae98943777301de98cb5c1d67bc89f0c4642b52/src/modules/examples.ts#L593-L641)

from delitemwithatt.

redleafnew avatar redleafnew commented on June 1, 2024

有些用了工具箱的函数,可能需要改造。

from delitemwithatt.

fredericky123 avatar fredericky123 commented on June 1, 2024

我估计是看不懂,不太会改造了😭

from delitemwithatt.

fredericky123 avatar fredericky123 commented on June 1, 2024
image 或者这里我想把alt都修改为ctrl,应该到哪里修改呢,这样在mac下估计就能运行了 image

from delitemwithatt.

fredericky123 avatar fredericky123 commented on June 1, 2024

或者,现在是不是可以结合action &tags测试出修饰键是什么,如果可以通过run javascript测试出来的话,我帮助测试一下
image

from delitemwithatt.

fredericky123 avatar fredericky123 commented on June 1, 2024
image

if (data.keyboard === control,${key_del_att}) {
HelperExampleFactory.delAtt();
console.log("control+" + key_del_att + " pressed");
}
询问gpt后的一些结果

from delitemwithatt.

redleafnew avatar redleafnew commented on June 1, 2024

https://github.com/redleafnew/delitemwithatt/releases/tag/0.1.05 老的版本你找找,看看,

from delitemwithatt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.