Преглед изворни кода

:alien: bugfix due to twitter CSP

LI JIAHAO пре 6 година
родитељ
комит
b3ea20852a
4 измењених фајлова са 4 додато и 2 уклоњено
  1. 1 1
      dist/helper.js
  2. 1 0
      dist/webshot.js
  3. 1 1
      src/helper.ts
  4. 1 0
      src/webshot.ts

+ 1 - 1
dist/helper.js

@@ -6,7 +6,7 @@ function default_1(message) {
     message = message.replace('\\\"', '\\0x22');
     message = message.replace('\\\'', '\\0x27');
     const strs = message.match(/'[\s\S]*?'|"[\s\S]*?"|\S*\[CQ:[\s\S]*?\]\S*|\S+/mg);
-    const cmd = strs.length ? strs[0].length ? strs[0].substring(0, 1) === '/' ? strs[0].substring(1) : '' : '' : '';
+    const cmd = strs ? strs.length ? strs[0].length ? strs[0].substring(0, 1) === '/' ? strs[0].substring(1) : '' : '' : '' : '';
     const args = strs.slice(1).map(arg => {
         arg = arg.replace(/^["']+|["']+$/g, '');
         arg = arg.replace('\\0x27', '\\\'');

+ 1 - 0
dist/webshot.js

@@ -23,6 +23,7 @@ class Webshot extends CallableInstance {
                         height,
                         isMobile: true,
                     }))
+                        .then(() => page.setBypassCSP(true))
                         .then(() => page.goto(url))
                         .then(() => page.addStyleTag({
                         content: 'html{zoom:2}header{display:none!important}path[d=\'M20.207 7.043a1 1 0 0 0-1.414 0L12 13.836 5.207 7.043a1 1 0 0 0-1.414 1.414l7.5 7.5a.996.996 0 0 0 1.414 0l7.5-7.5a1 1 0 0 0 0-1.414z\'],div[role=\'button\']{display: none;}',

+ 1 - 1
src/helper.ts

@@ -9,7 +9,7 @@ export default function (message: string): ICommand {
   message = message.replace('\\\"', '\\0x22');
   message = message.replace('\\\'', '\\0x27');
   const strs = message.match(/'[\s\S]*?'|"[\s\S]*?"|\S*\[CQ:[\s\S]*?\]\S*|\S+/mg);
-  const cmd = strs.length ? strs[0].length ? strs[0].substring(0, 1) === '/' ? strs[0].substring(1) : '' : '' : '';
+  const cmd = strs ? strs.length ? strs[0].length ? strs[0].substring(0, 1) === '/' ? strs[0].substring(1) : '' : '' : '' : '';
   const args = strs.slice(1).map(arg => {
     arg = arg.replace(/^["']+|["']+$/g, '');
     arg = arg.replace('\\0x27', '\\\'');

+ 1 - 0
src/webshot.ts

@@ -35,6 +35,7 @@ class Webshot extends CallableInstance {
               height,
               isMobile: true,
             }))
+            .then(() => page.setBypassCSP(true))
             .then(() => page.goto(url))
             .then(() => page.addStyleTag({
               content: 'html{zoom:2}header{display:none!important}path[d=\'M20.207 7.043a1 1 0 0 0-1.414 0L12 13.836 5.207 7.043a1 1 0 0 0-1.414 1.414l7.5 7.5a.996.996 0 0 0 1.414 0l7.5-7.5a1 1 0 0 0 0-1.414z\'],div[role=\'button\']{display: none;}',