|
|
@@ -3,7 +3,12 @@
|
|
|
[dommy.core :as dom]
|
|
|
[frontend.util :as util]
|
|
|
[frontend.db :as db]
|
|
|
+ [frontend.db.model :as db-model]
|
|
|
+ [frontend.config :as config]
|
|
|
[frontend.state :as state]
|
|
|
+ [frontend.storage :as storage]
|
|
|
+ [frontend.fs :as fs]
|
|
|
+ [frontend.loader :refer [load]]
|
|
|
[goog.dom :as gdom]
|
|
|
[goog.object :as gobj]
|
|
|
[clojure.string :as string]
|
|
|
@@ -95,11 +100,49 @@
|
|
|
[]
|
|
|
(when-let [style (or
|
|
|
(state/get-custom-css-link)
|
|
|
- (db/get-custom-css)
|
|
|
+ (db-model/get-custom-css)
|
|
|
;; (state/get-custom-css-link)
|
|
|
)]
|
|
|
(util/add-style! style)))
|
|
|
|
|
|
+(def *js-execed (atom #{}))
|
|
|
+
|
|
|
+(defn exec-js-if-exists-&-allowed!
|
|
|
+ []
|
|
|
+ (when-let [href (or
|
|
|
+ (state/get-custom-js-link)
|
|
|
+ (config/get-custom-js-path))]
|
|
|
+ (let [k (str "ls-js-allowed-" href)
|
|
|
+ execed #(swap! *js-execed conj href)
|
|
|
+ execed? (contains? @*js-execed href)
|
|
|
+ ask-allow #(let [r (js/confirm "Found the custom.js file, is it allowed to execute?
|
|
|
+ (If you don't understand the content of this file, it is recommended
|
|
|
+ not to allow execution, which has certain security risks.)")]
|
|
|
+ (if r
|
|
|
+ (storage/set k (js/Date.now))
|
|
|
+ (storage/set k false))
|
|
|
+ r)
|
|
|
+ allowed! (storage/get k)
|
|
|
+ should-ask? (or (nil? allowed!)
|
|
|
+ (> (- (js/Date.now) allowed!) 604800))]
|
|
|
+ (when (and (not execed?)
|
|
|
+ (not= false allowed!))
|
|
|
+ (if (string/starts-with? href "http")
|
|
|
+ (when (or (not should-ask?)
|
|
|
+ (ask-allow))
|
|
|
+ (load href #(do (js/console.log "[custom js]" href) (execed))))
|
|
|
+ (util/p-handle
|
|
|
+ (fs/read-file "" href)
|
|
|
+ #(when-let [scripts (and % (string/trim %))]
|
|
|
+ (when-not (string/blank? scripts)
|
|
|
+ (if (or (not should-ask?) (ask-allow))
|
|
|
+ (try
|
|
|
+ (do
|
|
|
+ (js/eval scripts)
|
|
|
+ (execed))
|
|
|
+ (catch js/Error e
|
|
|
+ (js/console.error "[custom js]" e))))))))))))
|
|
|
+
|
|
|
(defn toggle-wide-mode!
|
|
|
[]
|
|
|
(let [wide? (state/get-wide-mode?)
|