diff --git a/WebShell.xcodeproj/project.pbxproj b/WebShell.xcodeproj/project.pbxproj index 12170d6..1eff452 100755 --- a/WebShell.xcodeproj/project.pbxproj +++ b/WebShell.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 6E6055711C5EA6DC0099AD18 /* WebshellViewDid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E6055701C5EA6DC0099AD18 /* WebshellViewDid.swift */; }; 6EA8D1571C5C0BCA004534F9 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EA8D1561C5C0BCA004534F9 /* StringExtension.swift */; }; 6EA8D1591C5C1240004534F9 /* navigator_geolocation_getCurrentPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EA8D1581C5C1240004534F9 /* navigator_geolocation_getCurrentPosition.swift */; }; + 6EFEB6A21CC00FB1001CF349 /* WebShellCustomInject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EFEB6A11CC00FB1001CF349 /* WebShellCustomInject.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -43,6 +44,7 @@ 6E6055701C5EA6DC0099AD18 /* WebshellViewDid.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebshellViewDid.swift; sourceTree = ""; }; 6EA8D1561C5C0BCA004534F9 /* StringExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = ""; }; 6EA8D1581C5C1240004534F9 /* navigator_geolocation_getCurrentPosition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = navigator_geolocation_getCurrentPosition.swift; sourceTree = ""; }; + 6EFEB6A11CC00FB1001CF349 /* WebShellCustomInject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebShellCustomInject.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -108,6 +110,7 @@ 6E60556C1C5EA5D00099AD18 /* WebShellCore.swift */, 6E60556E1C5EA6810099AD18 /* WebViewFunctions.swift */, 6E6055701C5EA6DC0099AD18 /* WebshellViewDid.swift */, + 6EFEB6A11CC00FB1001CF349 /* WebShellCustomInject.swift */, ); name = "WebShell Core"; sourceTree = ""; @@ -182,6 +185,7 @@ buildActionMask = 2147483647; files = ( 6E6055671C5EA2050099AD18 /* WebShellFileHandler.swift in Sources */, + 6EFEB6A21CC00FB1001CF349 /* WebShellCustomInject.swift in Sources */, 6E6055621C5EA0870099AD18 /* Notifications.swift in Sources */, 6E60556D1C5EA5D00099AD18 /* WebShellCore.swift in Sources */, 6EA8D1571C5C0BCA004534F9 /* StringExtension.swift in Sources */, diff --git a/WebShell/ViewController.swift b/WebShell/ViewController.swift index a57c8b4..fd7ec97 100755 --- a/WebShell/ViewController.swift +++ b/WebShell/ViewController.swift @@ -67,6 +67,12 @@ class ViewController: NSViewController, WebFrameLoadDelegate, WebUIDelegate, Web // run the app in debug mode? (Default: false) // will be overridden by xCode (runs with -NSDocumentRevisionsDebugMode YES) - "debugmode": false + "debugmode": false, + + // Please paste here the JavaScript you want to load on a website + "JSInject": "alert('x!=y');", + + // Please paste here the CSS you want to load on a website + "CSSInject": "body{background:orange !important;}" ] } diff --git a/WebShell/WebShellCustomInject.swift b/WebShell/WebShellCustomInject.swift new file mode 100755 index 0000000..ec07a7a --- /dev/null +++ b/WebShell/WebShellCustomInject.swift @@ -0,0 +1,49 @@ +// +// WebShellCustomInject.swift +// WebShell +// +// Created by Wesley de Groot on 14-04-16. +// Copyright © 2016 RandyLu. All rights reserved. +// + +import Foundation +import WebKit + +extension ViewController { + /** + _WSInjectJS + + Injects JavaScript in to a frame, or other position + + - Parameter jsContext: JSContext! + + - Note: @wdg #36 + */ + internal func _WSInjectJS(jsContext: JSContext!) { + // JSInject + if (SETTINGS["JSInject"] as! String != "") { + jsContext.evaluateScript(SETTINGS["JSInject"] as! String) + } + } + + /** + _WSInjectCSS + + Injects CSS in to a frame, or other position + + - Parameter jsContext: JSContext! + + - Note: @wdg #36 + */ + internal func _WSInjectCSS(jsContext: JSContext!) { + // CSSInject + if (SETTINGS["CSSInject"] as! String != "") { + let css:String = (SETTINGS["CSSInject"] as! String) + .stringByReplacingOccurrencesOfString("\n", withString: "") + .stringByReplacingOccurrencesOfString("\r", withString: "") + .stringByReplacingOccurrencesOfString("'", withString: "\\'") + + jsContext.evaluateScript("var css='\(css)',head=document.head,style=document.createElement('style');style.type='text/css';if (style.styleSheet){style.styleSheet.cssText = css;}else{style.appendChild(document.createTextNode(css));}head.appendChild(style);") + } + } +} \ No newline at end of file diff --git a/WebShell/WebShellInjector.swift b/WebShell/WebShellInjector.swift index 8468583..6e39191 100755 --- a/WebShell/WebShellInjector.swift +++ b/WebShell/WebShellInjector.swift @@ -173,6 +173,8 @@ extension ViewController { let nsObject: AnyObject? = NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"] jsContext.evaluateScript("window.webshell={version:'\(nsObject as! String)'};webshell=window.webshell;") + _WSInjectJS(jsContext) + _WSInjectCSS(jsContext) } // @wdg Add Localstorage Support diff --git a/WebShell/WebShellPageActions.swift b/WebShell/WebShellPageActions.swift index b24506f..f6dc3ad 100755 --- a/WebShell/WebShellPageActions.swift +++ b/WebShell/WebShellPageActions.swift @@ -111,8 +111,8 @@ extension ViewController { mainWebview.mainFrame.loadRequest(NSURLRequest(URL: URL!)) // Inject Webhooks - self.injectWebhooks(mainWebview.mainFrame.javaScriptContext) - self.loopThroughiFrames() +// self.injectWebhooks(mainWebview.mainFrame.javaScriptContext) +// self.loopThroughiFrames() } // @wdg Add Print Support