Skip to content

Tampermonkey breaks docx https://github.com/dolanmiu/docx #1600

Description

@m42e

(Please fill out the issue template with your details)

Expected Behavior

https://github.com/dolanmiu/docx works, even if some grants were present.

Actual Behavior

It works as long as no grants are present, as soon as there are @grants the example from here is no longer working

Specifications

  • Chromium: Version 105.0.5195.127
  • TM: 4.16.1
  • OS: Windows 11

Script

When replacing the line of the grant with @grant none it works.

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://*/*
// @grant         GM_setValue
// @require      https://cdn.jsdelivr.net/npm/docx@7.5.0/build/index.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/exceljs/4.3.0/exceljs.min.js
// @require      https://cdn.jsdelivr.net/npm/sweetalert2@11
// @require      https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js
// ==/UserScript==

 function generate() {
        const doc = new docx.Document({
          sections: [{
            properties: {},
            children: [
              new docx.Paragraph({
                children: [
                  new docx.TextRun("Hello World"),
                  new docx.TextRun({
                    text: "Foo Bar",
                    bold: true,
                  }),
                  new docx.TextRun({
                    text: "\tGithub is the best",
                    bold: true,
                  }),
                ],
              }),
            ],
          }]
        });

        docx.Packer.toBlob(doc).then(blob => {
          console.log(blob);
          saveAs(blob, "example.docx");
          console.log("Document created successfully");
        });
      }
      function onKeydown(evt){
        if (evt.altKey && evt.keyCode == 84) { // ALt + t: download
        generate()
            evt.preventDefault();
        }
      }
document.addEventListener('keydown', onKeydown, true);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions