Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mhaeuser committed Oct 14, 2022
0 parents commit 9740e0a
Show file tree
Hide file tree
Showing 41 changed files with 1,783 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Custom Search.xcodeproj/xcuserdata/
Custom Search.xcodeproj/project.xcworkspace/xcuserdata/
27 changes: 27 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright (C) 2022 Marvin Häuser. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#

--swiftversion 5.7

--maxwidth 80

--self insert

--wraparguments before-first
--wrapparameters before-first
--wrapcollections before-first
--wrapconditions before-first
--wraptypealiases before-first

--enable blankLineAfterImports
--enable blockComments
--enable isEmpty
--enable wrapConditionalBodies
--enable wrapEnumCases
--enable wrapSwitchCases

--disable redundantNilInit
--disable redundantRawValues
--disable redundantReturn
981 changes: 981 additions & 0 deletions Custom Search.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
29 changes: 29 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (C) 2022, Marvin Häuser
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# CustomSearch
11 changes: 11 additions & 0 deletions Shared (App)/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
63 changes: 63 additions & 0 deletions Shared (App)/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Shared (App)/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file added Shared (App)/Resources/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions Shared (Extension)/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.Safari.web-extension</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).SafariWebExtensionHandler</string>
</dict>
</dict>
</plist>
10 changes: 10 additions & 0 deletions Shared (Extension)/Resources/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extension_name": {
"message": "Custom Search",
"description": "The display name for the extension."
},
"extension_description": {
"message": "This is Custom Search. You should tell us what your extension does here.",
"description": "Description of what the extension does."
}
}
67 changes: 67 additions & 0 deletions Shared (Extension)/Resources/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const filter = {
url:
[
{urlPrefix: "https://", hostEquals: "www.google.com", pathEquals: "/search", queryPrefix: "client=safari&", queryContains: "&q=", querySuffix: "&ie=UTF-8&oe=UTF-8"},
{urlPrefix: "https://", hostEquals: "search.yahoo.com", pathEquals: "/search", queryPrefix: "ei=utf-8&fr=aaplw&p="},
{urlPrefix: "https://", hostEquals: "www.bing.com", pathEquals: "/search", queryPrefix: "q=", querySuffix: "&form=APMCS1&PC=APMC"},
{urlPrefix: "https://", hostEquals: "duckduckgo.com", pathEquals: "/", queryPrefix: "q=", querySuffix: "&t=osx"},
{urlPrefix: "https://", hostEquals: "www.ecosia.org", pathEquals: "/search", queryPrefix: "q=", querySuffix: "&tts=st_asaf_macos"}
],
types: ["main_frame"]
};

var query_url = "";

function updateQueryUrl(url) {
query_url = url || "";

if (query_url === "") {
browser.declarativeNetRequest.updateEnabledRulesets(
{ disableRulesetIds: [ "block_search" ] }
)
} else {
browser.declarativeNetRequest.updateEnabledRulesets(
{ enableRulesetIds: [ "block_search" ] }
)
}
};

function readSettings() {
function cacheSettings(result) {
updateQueryUrl(result.query_url)
};

function onError(error) {
console.log(`Error: ${error}`);
};

let getting = browser.storage.sync.get("query_url");
getting.then(cacheSettings, onError);
};

function settingsChanged(changes) {
if (Object.keys(changes).includes("query_url")) {
updateQueryUrl(changes["query_url"].newValue)
}
};

function before(details) {
if (query_url === "") {
return
}

const url = new URL(details.url);

var queryKey = "q";
if (url.hostname === "search.yahoo.com") {
queryKey = "p";
}

const query = encodeURIComponent(url.searchParams.get(queryKey));
browser.tabs.update(details.tabId, { url: query_url + query });
};

browser.storage.sync.onChanged.addListener(settingsChanged)
readSettings()

browser.webNavigation.onBeforeNavigate.addListener(before, filter);
47 changes: 47 additions & 0 deletions Shared (Extension)/Resources/block_search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[
{
"id": 1,
"priority": 1,
"action": { "type": "block" },
"condition": {
"urlFilter": "|https://www.google.com/search?client=safari&*&q=*&ie=UTF-8&oe=UTF-8|",
"resourceTypes": [ "main_frame" ]
}
},
{
"id": 2,
"priority": 1,
"action": { "type": "block" },
"condition": {
"urlFilter": "|https://search.yahoo.com/search?ei=utf-8&fr=aaplw&p=*",
"resourceTypes": [ "main_frame" ]
}
},
{
"id": 3,
"priority": 1,
"action": { "type": "block" },
"condition": {
"urlFilter": "|https://www.bing.com/search?q=*&form=APMCS1&PC=APMC|",
"resourceTypes": [ "main_frame" ]
}
},
{
"id": 4,
"priority": 1,
"action": { "type": "block" },
"condition": {
"urlFilter": "|https://duckduckgo.com/?q=*&t=osx|",
"resourceTypes": [ "main_frame" ]
}
},
{
"id": 5,
"priority": 1,
"action": { "type": "block" },
"condition": {
"urlFilter": "|https://www.ecosia.org/search?q=*&tts=st_asaf_macos|",
"resourceTypes": [ "main_frame" ]
}
}
]
Binary file added Shared (Extension)/Resources/images/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Shared (Extension)/Resources/images/icon-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Shared (Extension)/Resources/images/icon-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Shared (Extension)/Resources/images/icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Shared (Extension)/Resources/images/icon-64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Shared (Extension)/Resources/images/icon-96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions Shared (Extension)/Resources/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"manifest_version": 3,
"default_locale": "en",

"name": "__MSG_extension_name__",
"description": "__MSG_extension_description__",
"version": "1.0",

"icons": {
"48": "images/icon-48.png",
"96": "images/icon-96.png",
"128": "images/icon-128.png",
"256": "images/icon-256.png",
"512": "images/icon-512.png"
},

"background": {
"service_worker": "background.js"
},

"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/toolbar-icon-16.png",
"19": "images/toolbar-icon-19.png",
"32": "images/toolbar-icon-32.png",
"38": "images/toolbar-icon-38.png",
"48": "images/toolbar-icon-48.png",
"72": "images/toolbar-icon-72.png"
}
},

"declarative_net_request" : {
"rule_resources" : [{
"id": "block_search",
"enabled": true,
"path": "block_search.json"
}]
},

"permissions": [
"webNavigation",
"storage",
"declarativeNetRequest"
]
}
14 changes: 14 additions & 0 deletions Shared (Extension)/Resources/popup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:root {
color-scheme: light dark;
}

body {
padding: 10px;

font-family: system-ui;
text-align: center;
}

@media (prefers-color-scheme: dark) {
/* Dark Mode styles go here. */
}
16 changes: 16 additions & 0 deletions Shared (Extension)/Resources/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="popup.css">
<script type="module" src="popup.js"></script>
</head>
<body>
<strong>Custom Search</strong><br><br>
<label for="query_url">Search Engine URL prefix:</label><br><br>
<form>
<input type="text" id="query_url" name="query_url" size="40"><br><br>
<input type="submit" value="Save">
</form>
</body>
</html>
Loading

0 comments on commit 9740e0a

Please sign in to comment.