瀏覽代碼

BUGFIX #70: Updated 'CSS selector' operation to use vanilla JS instead of jQuery, also fixing root element selection issues.

n1474335 8 年之前
父節點
當前提交
35d74980a1
共有 6 個文件被更改,包括 16 次插入10 次删除
  1. 0 0
      build/prod/cyberchef.htm
  2. 0 0
      build/prod/index.html
  3. 0 0
      build/prod/scripts.js
  4. 1 1
      src/js/config/OperationConfig.js
  5. 12 6
      src/js/operations/Code.js
  6. 3 3
      src/static/stats.txt

文件差異過大導致無法顯示
+ 0 - 0
build/prod/cyberchef.htm


文件差異過大導致無法顯示
+ 0 - 0
build/prod/index.html


文件差異過大導致無法顯示
+ 0 - 0
build/prod/scripts.js


+ 1 - 1
src/js/config/OperationConfig.js

@@ -1987,7 +1987,7 @@ var OperationConfig = {
     },
     "CSS selector": {
         description: "Extract information from an HTML document with a CSS selector",
-        run: Code.runCssQuery,
+        run: Code.runCSSQuery,
         inputType: "string",
         outputType: "string",
         args: [

+ 12 - 6
src/js/operations/Code.js

@@ -378,24 +378,30 @@ var Code = {
      * CSS selector operation.
      *
      * @author Mikescher (https://github.com/Mikescher | https://mikescher.com)
+     * @author n1474335 [n1474335@gmail.com]
      * @param {string} input
      * @param {Object[]} args
      * @returns {string}
      */
-    runCssQuery: function(input, args) {
+    runCSSQuery: function(input, args) {
         var query = args[0],
-            delimiter = args[1];
+            delimiter = args[1],
+            parser = new DOMParser(),
+            html,
+            result;
+
+        if (!query.length || !input.length) {
+            return "";
+        }
 
-        var html;
         try {
-            html = $.parseHTML(input);
+            html = parser.parseFromString(input, "text/html");
         } catch (err) {
             return "Invalid input HTML.";
         }
 
-        var result;
         try {
-            result = $(html).find(query);
+            result = html.querySelectorAll(query);
         } catch (err) {
             return "Invalid CSS Selector. Details:\n" + err.message;
         }

+ 3 - 3
src/static/stats.txt

@@ -1,9 +1,9 @@
 212	source files
-115054	lines
+115060	lines
 4.3M	size
 
 142	JavaScript source files
-105894	lines
+105900	lines
 3.8M	size
 
 83	third party JavaScript source files
@@ -11,7 +11,7 @@
 3.0M	size
 
 59	first party JavaScript source files
-19636	lines
+19642	lines
 740K	size
 
 3.4M	uncompressed JavaScript size

部分文件因文件數量過多而無法顯示