Skip to content

Commit

Permalink
Added a example for Content Blockers
Browse files Browse the repository at this point in the history
  • Loading branch information
shu223 committed Aug 31, 2015
1 parent 10c204d commit 3aaf8a3
Show file tree
Hide file tree
Showing 13 changed files with 529 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ Retrieve audio unit components using AudioUnitComponentManager and apply them to

<img src="ResourcesForREADME/aucomponents.jpg" width="200">

###Content Blockers

Example for Content Blocker Extensions.

<img src="ResourcesForREADME/blocker.jpg" width="200">


###Attributes of New Filters

Expand Down
Binary file added ResourcesForREADME/blocker.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions TwitterHeaderBlocker/ActionRequestHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ActionRequestHandler.swift
// TwitterHeaderBlocker
//
// Created by Shuichi Tsutsumi on 8/31/15.
// Copyright © 2015 Shuichi Tsutsumi. All rights reserved.
//

import UIKit
import MobileCoreServices

class ActionRequestHandler: NSObject, NSExtensionRequestHandling {

func beginRequestWithExtensionContext(context: NSExtensionContext) {
let attachment = NSItemProvider(contentsOfURL: NSBundle.mainBundle().URLForResource("blockerList", withExtension: "json"))!

let item = NSExtensionItem()
item.attachments = [attachment]

context.completeRequestReturningItems([item], completionHandler: nil);
}

}
33 changes: 33 additions & 0 deletions TwitterHeaderBlocker/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>TwitterHeaderBlocker</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.Safari.content-blocker</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ActionRequestHandler</string>
</dict>
</dict>
</plist>
11 changes: 11 additions & 0 deletions TwitterHeaderBlocker/blockerList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"action": {
"type": "css-display-none",
"selector": "header"
},
"trigger": {
"url-filter": ".*"
}
}
]
23 changes: 23 additions & 0 deletions TwitterImageBlocker/ActionRequestHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ActionRequestHandler.swift
// TwitterImageBlocker
//
// Created by Shuichi Tsutsumi on 8/31/15.
// Copyright © 2015 Shuichi Tsutsumi. All rights reserved.
//

import UIKit
import MobileCoreServices

class ActionRequestHandler: NSObject, NSExtensionRequestHandling {

func beginRequestWithExtensionContext(context: NSExtensionContext) {
let attachment = NSItemProvider(contentsOfURL: NSBundle.mainBundle().URLForResource("blockerList", withExtension: "json"))!

let item = NSExtensionItem()
item.attachments = [attachment]

context.completeRequestReturningItems([item], completionHandler: nil);
}

}
33 changes: 33 additions & 0 deletions TwitterImageBlocker/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>TwitterImageBlocker</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.Safari.content-blocker</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ActionRequestHandler</string>
</dict>
</dict>
</plist>
10 changes: 10 additions & 0 deletions TwitterImageBlocker/blockerList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"action": {
"type": "block"
},
"trigger": {
"url-filter": "pbs.twimg.com"
}
}
]
Loading

0 comments on commit 3aaf8a3

Please sign in to comment.