diff --git a/gulpfile.js b/gulpfile.js index 3b8f02c..fa9e916 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -21,7 +21,7 @@ gulp.task('minify_base_code', function() { /* Remove internal UUIDs */ gulp.task('remove_UUIDs', function() { return gulp.src('.') - .pipe(exec('sh scripts/remove_UUIDs.sh')) + .pipe(exec('sh scripts/uuids.sh remove')) }); @@ -75,7 +75,7 @@ gulp.task('all', gulp.parallel('userChrome', 'userContent', function() { })); /* Publish */ -gulp.task('publish', gulp.series('remove_UUIDs', 'minify_base_code', 'userChrome', 'userContent', 'minify_final')); +gulp.task('publish', gulp.series('minify_base_code', 'userChrome', 'userContent', 'minify_final', 'remove_UUIDs')); @@ -83,5 +83,5 @@ gulp.task('publish', gulp.series('remove_UUIDs', 'minify_base_code', 'userChrome gulp.task('push', function() { return gulp.src('.') .pipe(exec('git push')) - .pipe(exec('sh scripts/add_UUIDs.sh')) + .pipe(exec('sh scripts/uuids.sh add')) }); diff --git a/scripts/ShadowFox_updater_linux.sh b/scripts/ShadowFox_updater_linux.sh deleted file mode 100644 index 891e6ea..0000000 --- a/scripts/ShadowFox_updater_linux.sh +++ /dev/null @@ -1,186 +0,0 @@ -#!/bin/bash - -### ShadowFox updater for Linux -## author: @overdodactyl -## version: 1.3 - -userChrome="https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/userChrome.css" -userContent="https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/userContent.css" -uuid_finder="https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/scripts/internal_UUID_finder.sh" -updater="https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/scripts/ShadowFox_updater_linux.sh" -script_filename="$(basename $0)" - -currdir=$(pwd) - -## get the full path of this script (readlink for Linux, greadlink for Mac with coreutils installed) -sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null) - -## fallback for Macs without coreutils - may cause problems if symbolic links are encountered -if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi - -## change directory to the Firefox profile directory -cd "$(dirname "${sfp}")" - -## Check if there's a newwer version of the updater script available -online_version="$(curl -s ${updater} | sed -n '5p')" -current_version="$(sed '5q;d' ${script_filename})" - -## Remove prefix -prefix='## version: ' -online_version=${online_version#$prefix} -current_version=${current_version#$prefix} - -if (( $(echo "$online_version > $current_version" | bc -l) )); then - echo -e "There is a new updater script available online. It will replace this one and be executed.\n" - mv ${script_filename} old_updater.sh - curl -O ${updater} && echo -e "\nThe latest updater script has been downloaded\n" - # make new file executable - chmod +x ${script_filename} - - # execute new updater script - ./${script_filename} - - # exit script - exit 1 -fi - -echo -e "This script should be run from inside your Firefox profile." - -echo -e "Updating userContent.css and userChrome.css for Firefox profile:\n$(pwd)" - -if [ -e chrome/userContent.css ]; then - echo -e "Your current userContent.css file for this profile will be backed up\nand the latest ShadowFox version from github will take its place." -else - echo -e "A userContent.css file does not exist in this profile.\nIf you continue, the latest ShadowFox version from github will be downloaded." -fi - -if [ -e chrome/userChrome.css ]; then - echo -e "Your current userChrome.css file for this profile will be backed up\nand the latest ShadowFox version from github will take its place." -else - echo -e "A userChrome.css file does not exist in this profile.\nIf you continue, the latest ShadowFox version from github will be downloaded." -fi - -read -p "Continue Y/N? " -n 1 -r -echo -e "\n\n" - -if [[ $REPLY =~ ^[Yy]$ ]]; then - - ## Make chrome directory if it doesn't exist - mkdir -p chrome; - - ## Move to chrome directory - cd chrome; - - ## Make ShadowFox_customization directory if it doesn't exist - mkdir -p ShadowFox_customization; - - ## Create all customization files if they don't exist - touch ./ShadowFox_customization/colorOverrides.css - touch ./ShadowFox_customization/internal_UUIDs.txt - touch ./ShadowFox_customization/userContent_customization.css - touch ./ShadowFox_customization/userChrome_customization.css - - if [ -e userChrome.css ] || [ -e userContent.css ] ; then - ## Make chrome backups folder if it doesn't extern - mkdir -p chrome_backups - fi - if [ -e userChrome.css ]; then - # backup current userChrome.css file - bakfile="userChrome.backup.$(date +"%Y-%m-%d_%H%M%S")" - mv userChrome.css "chrome_backups/${bakfile}" && echo "Your previous userChrome.css file was backed up: ${bakfile}" - fi - if [ -e userContent.css ]; then - # backup current userChrome.css file - bakfile="userContent.backup.$(date +"%Y-%m-%d_%H%M%S")" - mv userContent.css "chrome_backups/${bakfile}" && echo "Your previous userContent.css file was backed up: ${bakfile}" - fi - - # download latest ShadowFox userChrome.css - echo -e "Downloading latest ShadowFox userChrome.css file..." - curl -O ${userChrome} && echo "ShadowFox userChrome.css has been downloaded." - - # download latest ShadowFox userContent.css - echo -e "Downloading latest ShadowFox userContent.css file..." - curl -O ${userContent} && echo "ShadowFox userContent.css has been downloaded." - - echo -e "Would you like to auto-generate an internal_UUIDs.txt file based on your downloaded extensions?" - echo -e "If you do so, your current file will be backed up." - echo -e "WARNING: this step requires bash 4 to be installed.\n" - - read -p "Y/N? " -n 1 -r - echo -e "\n\n" - - if [[ $REPLY =~ ^[Yy]$ ]]; then - # backup current internal_UUIDs.txt file - if [ -s ./ShadowFox_customization/internal_UUIDs.txt ]; then - bakfile="internal_UUIDs.backup.$(date +"%Y-%m-%d_%H%M%S")" - mv ./ShadowFox_customization/internal_UUIDs.txt "chrome_backups/${bakfile}" && echo "Your previous internal_UUIDs.txt file was backed up: ${bakfile}" - fi - # download latest version of internal_UUID_finder.sh - echo "Downloading latest internal_UUID_finder.sh file..." - curl -o ./ShadowFox_customization/internal_UUID_finder.sh ${uuid_finder} && echo -e "\ninternal_UUID_finder.sh has been downloaded" - - # make internal_UUID_finder executable - chmod +x ShadowFox_customization/internal_UUID_finder.sh - - # execute file - ShadowFox_customization/internal_UUID_finder.sh - echo "internal_UUIDs.txt has been generated based on your downloaded extensions." - fi - - if [ -s ./ShadowFox_customization/internal_UUIDs.txt ]; then - ## Insert any UUIDs defined in internal_UUIDs.txt into userContent.css - while IFS='' read -r line || [[ -n "$line" ]]; do - IFS='=' read -r -a array <<< "$line" - sed -i "s/${array[0]}/${array[1]}/" "userContent.css" - done < "./ShadowFox_customization/internal_UUIDs.txt" - echo -e "Your internal UUIDs have been inserted." - else - echo -e "You have not defined any internal UUIDs for webextensions." - echo -e "If you choose not to do so, webextensions will not be styled with a dark theme and may have compatibility issues in about:addons." - echo -e "For more information, see here:" - echo -e "https://github.com/overdodactyl/ShadowFox/wiki/Altering-webextensions" - fi - - if [ -s ./ShadowFox_customization/colorOverrides.css ]; then - ## Delete everything inbetween override markers - sed -i '/--start-indicator-for-updater-scripts: black;/,/--end-indicator-for-updater-scripts: black;/{//!d;}' userContent.css - sed -i '/--start-indicator-for-updater-scripts: black;/,/--end-indicator-for-updater-scripts: black;/{//!d;}' userChrome.css - - ## Insert everything from colorOverrides.css - sed -i '/--start-indicator-for-updater-scripts: black;/ r ./ShadowFox_customization/colorOverrides.css' userContent.css - sed -i '/--start-indicator-for-updater-scripts: black;/ r ./ShadowFox_customization/colorOverrides.css' userChrome.css - - echo -e "Your custom colors have been set." - else - echo -e "You are using the default colors set by ShadowFox." - echo -e "You can customize the colors used by editing colorOverrides.css." - fi - - if [ -s ./ShadowFox_customization/userContent_customization.css ]; then - ## Append tweaks to the end of userContent.css - cat ./ShadowFox_customization/userContent_customization.css >> userContent.css - echo -e "Your custom userContent.css tweaks have been applied." - else - echo -e "You do not have any custom userContent.css tweaks." - echo -e "You can customize userContent.css using userContent_customization.css." - fi - - if [ -s ./ShadowFox_customization/userChrome_customization.css ]; then - ## Append tweaks to the end of userContent.css - cat ./ShadowFox_customization/userChrome_customization.css >> userChrome.css - echo -e "Your custom userChrome.css tweaks have been applied." - else - echo -e "You do not have any custom userChrome.css tweaks." - echo -e "You can customize userChrome.css using userChrome_customization.css." - fi - -else - echo -e "Process aborted" -fi - -## Delete old updater script -[ -e ./../old_updater.sh ] && rm ./../old_updater.sh - -## change directory back to the original working directory -cd "${currdir}" diff --git a/scripts/ShadowFox_updater_mac.sh b/scripts/ShadowFox_updater_mac.sh deleted file mode 100644 index 4f3c580..0000000 --- a/scripts/ShadowFox_updater_mac.sh +++ /dev/null @@ -1,226 +0,0 @@ -#!/usr/bin/env bash - -### ShadowFox updater for Mac -## author: @overdodactyl -## version: 1.5 - -userChrome="https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/userChrome.css" -userContent="https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/userContent.css" -uuid_finder="https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/scripts/internal_UUID_finder.sh" -updater="https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/scripts/ShadowFox_updater_mac.sh" -webextension_mappings="https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/scripts/webextension_mappings.txt" - -profilePath="$HOME/Library/Application Support/Firefox/Profiles" - -currdir=$(pwd) - -## get the full path of this script (readlink for Linux, greadlink for Mac with coreutils installed) -sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null) - -## fallback for Macs without coreutils - may cause problems if symbolic links are encountered -if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi - -## check to see if file is already in a profile directory -if [[ $sfp == "$profilePath"* ]]; then - ## change directory to the Firefox profile directory - cd "$(dirname "${sfp}")" -else - ## if only one profile exists, go to it - if [ $(find "$profilePath"/* -maxdepth 0 -type d | wc -l) -eq 1 ]; then - profileDirectory=$(echo "$profilePath"/*) - - cd "${profileDirectory}" - - ## if there are multiple directories, list them and let user choose - else - for d in "$profilePath"/* ; do - name=$(echo $d | sed 's/.*\.//') - echo $name - done - read -p "What profile would you like to update ShadowFox in? " -r - echo "" - - profileName=$REPLY - profileID=$(ls "$profilePath" | grep $profileName | sed -n 's/\([[:alnum:]]*\).*/\1/p') - - cd "${profilePath}/${profileID}.${profileName}" - fi -fi - -## Check if there's a newer version of the updater script available -online_version="$(curl -s ${updater} | sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p')" -path_to_script="$(dirname "${sfp}")/ShadowFox_updater_mac.sh" -current_version="$(sed -n '5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' "$path_to_script")" - -if (( $(echo "$online_version > $current_version" | bc -l) )); then - echo -e "There is a new updater script available online. It will replace this one and be executed.\n" - mv ShadowFox_updater_mac.sh old_updater.sh - curl -O ${updater} && echo -e "\nThe latest updater script has been downloaded\n" - # make new file executable - chmod +x ShadowFox_updater_mac.sh - - # execute new updater script - ./ShadowFox_updater_mac.sh - - # exit script - exit 1 -fi - -echo -e "Updating userContent.css and userChrome.css for Firefox profile:\n$(pwd)\n" - -if [ -e chrome/userContent.css ]; then - echo "Your current userContent.css file for this profile will be backed up and the latest ShadowFox version from github will take its place." -else - echo -e "A userContent.css file does not exist in this profile. If you continue, the latest ShadowFox version from github will be downloaded." -fi - -if [ -e chrome/userChrome.css ]; then - echo -e "Your current userChrome.css file for this profile will be backed up and the latest ShadowFox version from github will take its place.\n" -else - echo -e "A userChrome.css file does not exist in this profile. If you continue, the latest ShadowFox version from github will be downloaded.\n" -fi - -read -p "Continue Y/N? " -n 1 -r -echo -e "\n\n" - -if [[ $REPLY =~ ^[Yy]$ ]]; then - - ## Make chrome directory if it doesn't exist - mkdir -p chrome; - - ## Move to chrome directory - cd chrome; - - ## Make ShadowFox_customization directory if it doesn't exist - mkdir -p ShadowFox_customization; - - ## Create all customization files if they don't exist - touch ./ShadowFox_customization/colorOverrides.css - touch ./ShadowFox_customization/internal_UUIDs.txt - touch ./ShadowFox_customization/userContent_customization.css - touch ./ShadowFox_customization/userChrome_customization.css - - if [ -e userChrome.css ]; then - # backup current userChrome.css file - mkdir -p chrome_backups - bakfile="userChrome.backup.$(date +"%Y-%m-%d_%H%M%S")" - mv userChrome.css "chrome_backups/${bakfile}" && echo "Your previous userChrome.css file was backed up: ${bakfile}" - fi - if [ -e userContent.css ]; then - # backup current userChrome.css file - mkdir -p chrome_backups - bakfile="userContent.backup.$(date +"%Y-%m-%d_%H%M%S")" - mv userContent.css "chrome_backups/${bakfile}" && echo "Your previous userContent.css file was backed up: ${bakfile}" - fi - - # download latest ShadowFox userChrome.css - echo "Downloading latest ShadowFox userChrome.css file..." - curl -O ${userChrome} && echo -e "\nShadowFox userChrome.css has been downloaded" - - # download latest ShadowFox userContent.css - echo "Downloading latest ShadowFox userContent.css file..." - curl -O ${userContent} && echo -e "\nShadowFox userContent.css has been downloaded\n" - - echo "Would you like to auto-generate an internal_UUIDs.txt file based on your downloaded extensions?" - echo "If you do so, your current file will be backed up." - echo -e "WARNING: this step requires bash 4 to be installed.\n" - - read -p "Y/N? " -n 1 -r - echo -e "\n\n" - - if [[ $REPLY =~ ^[Yy]$ ]]; then - - # Check for bash version 4 or higher - if [ $(bash -c 'echo ${BASH_VERSINFO[0]}') -lt 4 ]; then - echo "Please install bash version 4 or higher." - exit 1 - fi - - # backup current internal_UUIDs.txt file - if [ -s ./ShadowFox_customization/internal_UUIDs.txt ]; then - bakfile="internal_UUIDs.backup.$(date +"%Y-%m-%d_%H%M%S")" - mv ./ShadowFox_customization/internal_UUIDs.txt "chrome_backups/${bakfile}" && echo "Your previous internal_UUIDs.txt file was backed up: ${bakfile}" - fi - - ## write webextension_mappings.txt to variable - web_ex=$(curl -s ${webextension_mappings}) - - ## declare directory - declare -A styled=() - - ## Generate dictionary from file - while IFS="|" read -r webex_name webex_id; do - styled["$webex_id"]+="$webex_name" - done <<< "$web_ex" - - ## Get installed extesnsions from prefs.js - line=$(sed -n -e 's/^user_pref("extensions.webextensions.uuids", "{\(.*\).*}");/\1/p' ../prefs.js) - - ## Write to internal_UUIDs - IFS=',' read -ra EXTS <<< "$line" - for i in "${EXTS[@]}"; do - id=$(echo $i | sed -n 's/.*"\(.*\)\\":.*/\1/p') - uuid=$(echo $i | sed -n 's/.*"\(.*\)\\".*/\1/p') - if [[ -n "${styled[$id]}" ]] - then - echo "${styled[$id]}_UUID=$uuid" >> 'ShadowFox_customization/internal_UUIDs.txt' - fi; - done - fi - - if [ -s ./ShadowFox_customization/internal_UUIDs.txt ]; then - ## Insert any UUIDs defined in internal_UUIDs.txt into userContent.css - while IFS='' read -r line || [[ -n "$line" ]]; do - IFS='=' read -r -a array <<< "$line" - sed -i '' "s/${array[0]}/${array[1]}/" "userContent.css" - done < "./ShadowFox_customization/internal_UUIDs.txt" - echo -e "Your internal UUIDs have been inserted.\n" - else - echo "You have not defined any internal UUIDs for webextensions." - echo "If you choose not to do so, webextensions will not be styled with a dark theme and may have compatibility issues in about:addons." - echo "For more information, see here:" - echo -e "https://github.com/overdodactyl/ShadowFox/wiki/Altering-webextensions\n" - fi - - if [ -s ./ShadowFox_customization/colorOverrides.css ]; then - ## Delete everything inbetween override markers - sed -i '' '/--start-indicator-for-updater-scripts: black;/,/--end-indicator-for-updater-scripts: black;/{//!d;}' userContent.css - sed -i '' '/--start-indicator-for-updater-scripts: black;/,/--end-indicator-for-updater-scripts: black;/{//!d;}' userChrome.css - - ## Insert everything from colorOverrides.css - sed -i '' '/--start-indicator-for-updater-scripts: black;/ r ./ShadowFox_customization/colorOverrides.css' userContent.css - sed -i '' '/--start-indicator-for-updater-scripts: black;/ r ./ShadowFox_customization/colorOverrides.css' userChrome.css - - echo -e "Your custom colors have been set.\n" - else - echo "You are using the default colors set by ShadowFox." - echo -e "You can customize the colors used by editing colorOverrides.css.\n" - fi - - if [ -s ./ShadowFox_customization/userContent_customization.css ]; then - ## Append tweaks to the end of userContent.css - cat ./ShadowFox_customization/userContent_customization.css >> userContent.css - echo -e "Your custom userContent.css tweaks have been applied.\n" - else - echo "You do not have any custom userContent.css tweaks." - echo -e "You can customize userContent.css using userContent_customization.css.\n" - fi - - if [ -s ./ShadowFox_customization/userChrome_customization.css ]; then - ## Append tweaks to the end of userContent.css - cat ./ShadowFox_customization/userChrome_customization.css >> userChrome.css - echo -e "Your custom userChrome.css tweaks have been applied.\n" - else - echo "You do not have any custom userChrome.css tweaks." - echo -e "You can customize userChrome.css using userChrome_customization.css.\n" - fi - -else - echo "Process aborted" -fi - -## Delete old updater script -[ -e ./../old_updater.sh ] && rm ./../old_updater.sh - -## change directory back to the original working directory -cd "${currdir}" diff --git a/scripts/ShadowFox_updater_windows.vbs b/scripts/ShadowFox_updater_windows.vbs deleted file mode 100644 index cf38f5b..0000000 --- a/scripts/ShadowFox_updater_windows.vbs +++ /dev/null @@ -1,452 +0,0 @@ -option explicit - -' ShadowFox updater for Windows -' author: @CarlColijn -' version: 1.1 -' ^^^ ensure the version number is a numeric float value! - -' the download urls of the files -const chromeFileURL = "https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/userChrome.css" -const contentFileURL = "https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/userContent.css" -const updaterFileURL = "https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/scripts/ShadowFox_updater_windows.vbs" - -' set up the common worker objects and flags -dim vbSection: vbSection = vbNewLine & vbNewLine -const forReading = 1 -const adTypeBinary = 1 -const adTypeText = 2 -const adSaveCreateOverWrite = 2 -dim fso: set fso = createObject("Scripting.FileSystemObject") -dim regEx: set regEx = createObject("VBScript.RegExp") -regEx.global = true -regEx.ignoreCase = true -dim shell: set shell = createObject("WScript.Shell") - -' vb's IIf replacement -function iif(condition, trueValue, falseValue) - if condition then - iif = trueValue - else - iif = falseValue - end if -end function - -' does a regex newline-agnostic replacement on the given text -function regExNLReplace(text, pattern, replaceText) - ' ensure newlines are absent, since VBScript regex can't match 'em - dim encodedText: encodedText = replace(replace(text, vbCr, chr(1)), vbLf, chr(2)) - - ' do the regex replace - regEx.pattern = pattern - dim replacedText: replacedText = regEx.replace(encodedText, replaceText) - - ' and decode the newlines again - regExNLReplace = replace(replace(replacedText, chr(1), vbCr), chr(2), vbLf) -end function - -' left-pads the given text to the given length with the given character -' the text is not truncated if longer than the given length -function leftPad(text, length, padChar) - if len(text) >= length then - leftPad = text - else - leftPad = string(length - len(text), padChar) & text - end if -end function - -' gets a yyyy-mm-dd_hh-mm timestamp -function dateTimeStamp() - dim present: present = now - dateTimeStamp = year(present) & "-" & leftPad(month(present), 2, "0") & "-" & leftPad(day(present), 2, "0") & "_" & leftPad(hour(present), 2, "0") & "-" & leftPad(minute(present), 2, "0") & "-" & leftPad(second(present), 2, "0") -end function - -' backs up the given file -' creates the backup folder if it doesn't exist yet -' returns the used backup file name -function backupFile(sourceFilePath, backupFolderPath) - ' determine the backup filename - dim backupFileName: backupFileName = fso.getBaseName(sourceFilePath) & ".backup." & dateTimeStamp() & "." & fso.getExtensionName(sourceFilePath) - dim backupFilePath: backupFilePath = fso.buildPath(backupFolderPath, backupFileName) - - ' ensure the backup folder is there - if not fso.folderExists(backupFolderPath) then - call fso.createFolder(backupFolderPath) - end if - - ' backup the file - call fso.moveFile(sourceFilePath, backupFilePath) - - ' and tell where the backup ended up - backupFile = backupFileName -end function - -' reads the given file's content -function readFileContent(filePath) - if fso.getFile(filePath).size = 0 then - readFileContent = "" - else - readFileContent = fso.openTextFile(filePath, forReading).readAll() - end if -end function - -' writes the given file's content -function writeFileContent(filePath, content) - call fso.createTextFile(filePath, true).write(content) -end function - -' downloads the given file -' returns the content and if the download succeeded -function downloadFile(url, content) - on error resume next - ' download the file content - dim xmlHttp: set xmlHttp = createObject("Microsoft.XMLHTTP") - call xmlHttp.Open("GET", url, false) - call xmlHttp.Send() - if err.number = 0 then - ' done -> convert it - dim stream: set stream = createobject("ADODB.Stream") - with stream - .type = adTypeBinary - call .open - call .write(xmlHttp.responseBody) - .position = 0 - .type = adTypeText - .charSet = "us-ascii" - content = .readText() - end with - end if - - ' and tell if all is OK - downloadFile = err.number = 0 - on error goto 0 -end function - -' downloads and saves the given file to the given location -' returns if the download succeeded -function downloadAndSaveFile(url, filePath) - ' download the file's content - dim content - downloadAndSaveFile = downloadFile(url, content) - if downloadAndSaveFile then - ' done -> save it's content - call writeFileContent(filePath, content) - end if -end function - -' ensures consistent line endings in the given text (to just crLf) -function normalizeLineEndings(text) - normalizeLineEndings = replace(replace(text, vbCrLf, vbLf), vbCr, vbLf) -end function - -' ensures the given file is present -' returns the file's content, or "" if not present -function processCustomizationFile(filePath) - if fso.fileExists(filePath) then - processCustomizationFile = readFileContent(filePath) - else - processCustomizationFile = "" - call fso.createTextFile(filePath, true) - end if -end function - -' reads in the given ini file -' returns a dict of dicts, where the outer dict keys on the sections and the inner dicts on the keys -function readIni(iniFilePath) - ' get the ini's content - dim iniLines: iniLines = split(normalizeLineEndings(readFileContent(iniFilePath)), vbLf) - - ' and parse it - set readIni = CreateObject("Scripting.Dictionary") - dim currentSection: set currentSection = Nothing - dim nextLine - for each nextLine in iniLines - ' get the next line - nextLine = trim(nextLine) - if len(nextLine) > 0 then - ' done -> look what we have - if left(nextLine, 1) = "[" then - ' a section -> switch to it - dim nextSectionName: nextSectionName = mid(nextLine, 2, len(nextLine) - 2) - if readIni.exists(nextSectionName) then - set currentSection = readIni.item(nextSectionName) - else - set currentSection = CreateObject("Scripting.Dictionary") - set readIni.item(nextSectionName) = currentSection - end if - else - ' a key -> add it - dim endKeyPos: endKeyPos = inStr(nextLine, "=") - if endKeyPos >= 1 and not currentSection is nothing then - dim nextKey: nextKey = trim(left(nextLine, endKeyPos - 1)) - dim nextValue: nextValue = mid(nextLine, endKeyPos + 1) - currentSection.item(nextKey) = nextValue - end if - end if - end if - next -end function - -' gets the path to the profile folder to update -' returns "" if more than one profile exists but the user cancels -function getProfileFolderPath() - ' determine where the FireFox files are located - dim userDataFolderPath: userDataFolderPath = shell.ExpandEnvironmentStrings("%APPDATA%\Mozilla\FireFox") - dim profileIniFilePath: profileIniFilePath = fso.buildPath(userDataFolderPath, "profiles.ini") - - ' determine where we are located - dim ourPath: ourPath = fso.getParentFolderName(wscript.scriptFullName) - - ' get the profiles configuration - dim iniContent: set iniContent = readIni(profileIniFilePath) - - ' extract the names & paths of the profiles found - dim profilePaths: set profilePaths = CreateObject("Scripting.Dictionary") - profilePaths.compareMode = VBTextCompare - dim sectionName - dim defaultProfileName: defaultProfileName = "" - dim forcedProfilePath: forcedProfilePath = "" - for each sectionName in iniContent.keys() - if lcase(left(sectionName, 7)) = "profile" then - dim section: set section = iniContent.item(sectionName) - dim name: name = section.item("Name") - dim path - if section.item("IsRelative") = "0" then - path = section.item("Path") - else - path = fso.buildPath(userDataFolderPath, section.item("Path")) - end if - if section.exists("Default") then - defaultProfileName = name - end if - if strComp(left(ourPath, len(path)), path, vbTextCompare) = 0 then - forcedProfilePath = path - end if - profilePaths.item(name) = path - end if - next - - ' and look what situation we're in - if len(forcedProfilePath) > 0 then - ' running from within a profile -> use that one - getProfileFolderPath = forcedProfilePath - elseif profilePaths.count = 1 then - ' just one profile found -> use it - getProfileFolderPath = profilePaths.items()(0) - else - ' more than one profile found -> ask which one to use - do - dim prompt: prompt = "Which profile would you like to update ShadowFox in?" - dim profileName - dim profileChosen: profileChosen = true - for each profileName in profilePaths.keys() - prompt = prompt & vbNewLine & profileName & ": """ & profilePaths.item(profileName) & """" - next - dim chosenProfileName: chosenProfileName = trim(inputBox(prompt, "ShadowFox updater", defaultProfileName)) - if len(chosenProfileName) = 0 then - getProfileFolderPath = "" - else - if profilePaths.exists(chosenProfileName) then - getProfileFolderPath = profilePaths.item(chosenProfileName) - else - ' illegal one -> tell - call msgbox("The profile """ & chosenProfileName & """ doesn't exist; please select one from the list.", vbOKOnly & vbExclamation, "ShadowFox updater") - profileChosen = false - end if - end if - loop while not profileChosen - end if -end function - -' gets the version of the given updater file -' return "" if not found -function getUpdaterVersion(updaterSourceCode) - regEx.pattern = "' version: (.*)" - dim matches: set matches = regEx.execute(updaterSourceCode) - if matches.count > 0 then - getUpdaterVersion = matches(0).subMatches(0) - else - getUpdaterVersion = "" - end if -end function - -' gets the latest version of the updater -' returns if a newer version was installed -function getLatestUpdater(updaterFilePath) - ' download the source of the latest updater - getLatestUpdater = false - dim latestSource - if downloadFile(updaterFileURL, latestSource) then - ' done -> extract it's version - dim latestVersion: latestVersion = getUpdaterVersion(latestSource) - - ' extract our version - dim ourVersion: ourVersion = getUpdaterVersion(readFileContent(updaterFilePath)) - - ' and see if there is a newer version available - if latestVersion > ourVersion then - ' yes -> replace us with it - dim updaterPath: updaterPath = fso.getParentFolderName(updaterFilePath) - call backupFile(updaterFilePath, updaterPath) - call writeFileContent(updaterFilePath, latestSource) - getLatestUpdater = true - end if - end if -end function - - - -' ensure we're up-to-date -dim ourPath: ourPath = wscript.scriptFullName -if getLatestUpdater(ourPath) then - ' we weren't, but are now -> tell we're going to run it - call msgbox("There is a new updater script available online. Your old version has been backed up, and the new one has been downloaded and has replaced this one. It will now be executed instead.", vbOKOnly, "ShadowFox updater") - call shell.run("""" & ourPath & """", , false) -else - ' we are -> look which profile folder to update - dim profileFolderPath: profileFolderPath = getProfileFolderPath() - if len(profileFolderPath) > 0 then - ' done -> determine where the files need to go - dim chromeFolderPath: chromeFolderPath = fso.buildPath(profileFolderPath, "chrome") - dim backupFolderPath: backupFolderPath = fso.buildPath(profileFolderPath, "chrome_backups") - dim chromeFilePath: chromeFilePath = fso.buildPath(chromeFolderPath, "userChrome.css") - dim contentFilePath: contentFilePath = fso.buildPath(chromeFolderPath, "userContent.css") - dim customizationsFolderPath: customizationsFolderPath = fso.buildPath(chromeFolderPath, "ShadowFox_customization") - dim colorOverridesFilePath: colorOverridesFilePath = fso.buildPath(customizationsFolderPath, "colorOverrides.css") - dim internalUUIDsFilePath: internalUUIDsFilePath = fso.buildPath(customizationsFolderPath, "internal_UUIDs.txt") - dim chromeCustomizationsFilePath: chromeCustomizationsFilePath = fso.buildPath(customizationsFolderPath, "userChrome_customization.css") - dim contentCustomizationsFilePath: contentCustomizationsFilePath = fso.buildPath(customizationsFolderPath, "userContent_customization.css") - - ' and ask if we may continue - dim prompt: prompt = "Updating userContent.css and userChrome.css for Firefox profile:" & vbNewLine & chromeFolderPath & vbNewLine - if fso.fileExists(contentFilePath) then - prompt = prompt & vbNewLine & _ - "Your current userContent.css file for this profile will be backed up and the latest ShadowFox version from github will take its place." - else - prompt = prompt & vbNewLine & _ - "A userContent.css file does not exist in this profile. If you continue, the latest ShadowFox version from github will be downloaded." - end if - if fso.fileExists(chromeFilePath) then - prompt = prompt & vbNewLine & _ - "Your current userChrome.css file for this profile will be backed up and the latest ShadowFox version from github will take its place." - else - prompt = prompt & vbNewLine & _ - "A userChrome.css file does not exist in this profile. If you continue, the latest ShadowFox version from github will be downloaded." - end if - if vbNo = msgBox(prompt & vbSection & "Continue?", vbYesNo + vbDefaultButton2 + vbQuestion, "ShadowFox updater") then - ' no -> tell - call msgBox("Process aborted.", vbOKOnly, "ShadowFox updater") - else - ' yes -> ensure the folders are present - if not fso.folderExists(chromeFolderPath) then - call fso.createFolder(chromeFolderPath) - end if - if not fso.folderExists(customizationsFolderPath) then - call fso.createFolder(customizationsFolderPath) - end if - - ' backup any existing files - prompt = "Installing new ShadowFox files." - if fso.fileExists(contentFilePath) then - prompt = prompt & vbNewLine & _ - "Your previous userContent.css file was backed up: " & backupFile(contentFilePath, backupFolderPath) - end if - if fso.fileExists(chromeFilePath) then - prompt = prompt & vbNewLine & _ - "Your previous userChrome.css file was backed up: " & backupFile(chromeFilePath, backupFolderPath) - end if - - ' download the latest versions - dim allOK - allOK = true - if _ - not downloadAndSaveFile(chromeFileURL, chromeFilePath) or _ - not downloadAndSaveFile(contentFileURL, contentFilePath) _ - then - ' error downloading -> tell - prompt = prompt & vbSection & _ - "There was an error downloading the latest ShadowFox userContent.css and/or userChrome.css files." - allOK = false - else - ' done -> tell - prompt = prompt & vbSection & _ - "ShadowFox userContent.css and userChrome.css have been downloaded." - - ' read their content to manipulate it - dim chromeFileContent: chromeFileContent = readFileContent(chromeFilePath) - dim contentFileContent: contentFileContent = readFileContent(contentFilePath) - - ' do any extension UUID replacements - dim internalUUIDs: internalUUIDs = processCustomizationFile(internalUUIDsFilePath) - if len(internalUUIDs) = 0 then - prompt = prompt & vbSection & _ - "You have not defined any internal UUIDs for webextensions." & vbNewLine & _ - "If you choose not to do so, webextensions will not be styled with a dark theme and may have compatibility issues in about:addons." & vbNewLine & _ - "For more information, see here:" & vbNewLine & _ - "https://github.com/overdodactyl/ShadowFox/wiki/Altering-webextensions" - else - dim internalUUID - for each internalUUID in split(normalizeLineEndings(internalUUIDs), vbLf) - if instr(internalUUID, "=") > 0 then - dim replacementParts: replacementParts = split(internalUUID, "=") - regEx.pattern = replacementParts(0) - contentFileContent = regEx.replace(contentFileContent, replacementParts(1)) - end if - next - prompt = prompt & vbSection & _ - "Your internal UUIDs have been inserted." - end if - - ' process any color overrides - dim colorOverrides: colorOverrides = processCustomizationFile(colorOverridesFilePath) - if len(colorOverrides) = 0 then - prompt = prompt & vbSection & _ - "You are using the default colors set by ShadowFox." & vbNewLine & _ - "You can customize the colors used by editing colorOverrides.css." - else - const replacePattern = "(--start-indicator-for-updater-scripts: black;)(.*)(--end-indicator-for-updater-scripts: black;)" - dim replaceWith: replaceWith = "$1" & vbNewLine & colorOverrides & vbNewLine & "$3" - chromeFileContent = regExNLReplace(chromeFileContent, replacePattern, replaceWith) - contentFileContent = regExNLReplace(contentFileContent, replacePattern, replaceWith) - prompt = prompt & vbSection & _ - "Your custom colors have been set." - end if - - ' add on any overrides - dim contentCustomizations: contentCustomizations = processCustomizationFile(contentCustomizationsFilePath) - if len(contentCustomizations) = 0 then - prompt = prompt & vbSection & _ - "You do not have any custom userContent.css tweaks." & vbNewLine & _ - "You can customize userContent.css using userContent_customization.css." - else - contentFileContent = contentFileContent & vbSection & contentCustomizations - prompt = prompt & vbSection & _ - "Your custom userContent.css tweaks have been applied." - end if - dim chromeCustomizations: chromeCustomizations = processCustomizationFile(chromeCustomizationsFilePath) - if len(chromeCustomizations) = 0 then - prompt = prompt & vbSection & _ - "You do not have any custom userChrome.css tweaks." & vbNewLine & _ - "You can customize userChrome.css using userChrome_customization.css." - else - chromeFileContent = chromeFileContent & vbSection & chromeCustomizations - prompt = prompt & vbSection & _ - "Your custom userChrome.css tweaks have been applied." - end if - - ' write them out again - on error resume next - call fso.createTextFile(chromeFilePath, true).write(chromeFileContent) - call fso.createTextFile(contentFilePath, true).write(contentFileContent) - if err.number <> 0 then - allOK = false - prompt = prompt & vbSection & _ - "There was an error saving the customized versions of the userChrome.css and/or userContent.css files." - end if - on error goto 0 - end if - - ' and tell we're done - call msgBox(prompt, iif(allOK, vbInformation, vbExclamation), "ShadowFox updater") - end if - end if -end if diff --git a/scripts/add_UUIDs.sh b/scripts/add_UUIDs.sh deleted file mode 100644 index 22ff6ea..0000000 --- a/scripts/add_UUIDs.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -## Mac -## adds UUIDs found in internal_UUIDs.txt to their corresponding file in userContent-files/webextension-tweaks -## designed for users using userContent_imports.css -## entries in internal_UUIDs.txt should take on the following format: webextension_name_UUID=INTERNAL_UUID -## author: @overdodactyl -## version: 1.1 - -currdir=$(pwd) - -## get the full path of this script (readlink for Linux, greadlink for Mac with coreutils installed) -sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null) - -## fallback for Macs without coreutils - may cause problems if symbolic links are encountered -if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi - -## change directory to the Firefox profile directory -cd "$(dirname "${sfp}")" && cd .. - -## Insert any UUIDs defined in internal_UUIDs.txt into userContent.css -while IFS='' read -r line || [[ -n "$line" ]]; do - IFS='=' read -r -a array <<< "$line" - webextension_name=${array[0]%_UUID} - if [ -e css/userContent-files/webextension-tweaks/${webextension_name}.css ]; then - sed -i '' "s/${array[0]}/${array[1]}/" "css/userContent-files/webextension-tweaks/${webextension_name}.css" - fi - sed -i '' "s/${array[0]}/${array[1]}/" "css/userContent-files/webextension-tweaks/generic_style.css" - - -done < "internal_UUIDs.txt" diff --git a/scripts/internal_UUID_finder.sh b/scripts/internal_UUID_finder.sh deleted file mode 100755 index 76d00fc..0000000 --- a/scripts/internal_UUID_finder.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -### UUID finder for Mac -## author: @overdodactyl -## version: 1.1 - -## Get current mappings from online repo -webextension_mappings="https://raw.githubusercontent.com/overdodactyl/ShadowFox/master/scripts/webextension_mappings.txt" -web_ex=$(curl -s ${webextension_mappings}) - -## declare directory -declare -A styled=() - -## Generate dictionaries from file -while IFS="|" read -r webex_name webex_id; do - styled["$webex_id"]+="$webex_name" -done <<< "$web_ex" - -## Get installed extesnsions from prefs.js -line=$(sed -n -e 's/^user_pref("extensions.webextensions.uuids", "{\(.*\).*}");/\1/p' ../prefs.js) - -## Write to internal_UUIDs -IFS=',' read -ra EXTS <<< "$line" -for i in "${EXTS[@]}"; do - id=$(echo $i | sed -n 's/.*"\(.*\)\\":.*/\1/p') - uuid=$(echo $i | sed -n 's/.*"\(.*\)\\".*/\1/p') - if [[ -n "${styled[$id]}" ]] - then - echo "${styled[$id]}_UUID=$uuid" >> 'ShadowFox_customization/internal_UUIDs.txt' - fi; -done diff --git a/scripts/remove_UUIDs.sh b/scripts/remove_UUIDs.sh deleted file mode 100644 index 68276a1..0000000 --- a/scripts/remove_UUIDs.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -## Mac -## removes UUIDs found in internal_UUIDs.txt in their corresponding file in userContent-files/webextension-tweaks -## designed for users using userContent_imports.css -## entries in internal_UUIDs.txt should take on the following format: webextension_name_UUID=INTERNAL_UUID -## author: @overdodactyl -## version: 1.0 - -currdir=$(pwd) - -## get the full path of this script (readlink for Linux, greadlink for Mac with coreutils installed) -sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null) - -## fallback for Macs without coreutils - may cause problems if symbolic links are encountered -if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi - -## change directory to the Firefox profile directory -cd "$(dirname "${sfp}")" && cd .. - -## Insert any UUIDs defined in internal_UUIDs.txt into userContent.css -while IFS='' read -r line || [[ -n "$line" ]]; do - IFS='=' read -r -a array <<< "$line" - webextension_name=${array[0]%_UUID} - if [ -e css/userContent-files/webextension-tweaks/${webextension_name}.css ]; then - sed -i '' "s/${array[1]}/${array[0]}/" "css/userContent-files/webextension-tweaks/${webextension_name}.css" - fi - sed -i '' "s/${array[1]}/${array[0]}/" "css/userContent-files/webextension-tweaks/generic_style.css" -done < "internal_UUIDs.txt" diff --git a/scripts/uuids.sh b/scripts/uuids.sh new file mode 100644 index 0000000..4f04af2 --- /dev/null +++ b/scripts/uuids.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +## Mac +## arg1 - required: +## add: add UUIDs found in internal_UUID.txt to corresponding .css files +## remove: add UUIDs found in internal_UUID.txt to corresponding .css files +## arg2 - optional: +## nogen: don't generate internal_UUIDs.txt before adding/removing +## designed for users using userContent_imports.css +## entries in internal_UUIDs.txt should take on the following format: webextension_id=internal_UUID +## author: @overdodactyl +## version: 1.0 + +method=$1 +uuid_finder=${2:-gen} + +# Determine whether UUIDs will be inserted or removed +if [ $method = "add" ]; then + var1=0 + var2=1 + var3="inserted" +elif [ $method = "remove" ]; then + var1=1 + var2=0 + var3="removed" +else + echo "must pass argument add or remove" + exit 1 +fi + +currdir=$(pwd) +sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null) +if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi +cd "$(dirname "${sfp}")" && cd .. + +if [ $uuid_finder != "nogen" ]; then + ## Generate internal_UUIDs.txt + touch "scripts/internal_UUIDs.txt" + + ## Get installed extesnsions from prefs.js + line=$(sed -n -e 's/^user_pref("extensions.webextensions.uuids", "{\(.*\).*}");/\1/p' ./../../prefs.js) + + ## Clear internal_UUIDS.txt + > 'scripts/internal_UUIDs.txt' + + ## Write to internal_UUIDs + IFS=',' read -ra EXTS <<< "$line" + for i in "${EXTS[@]}"; do + id=$(echo $i | sed -n 's/.*"\(.*\)\\":.*/\1/p') + uuid=$(echo $i | sed -n 's/.*"\(.*\)\\".*/\1/p') + echo "$id=$uuid" >> 'scripts/internal_UUIDs.txt' + done + echo "scripts/internal_UUIDs.txt was created" +fi + + +## Insert/remove any UUIDs defined in internal_UUIDs.txt into userContent.css +while IFS='' read -r line || [[ -n "$line" ]]; do + IFS='=' read -r -a array <<< "$line" + webextension_name=${array[0]%_UUID} + for filename in css/userContent-files/webextension-tweaks/*.css; do + sed -i '' "s/${array[$var1]}/${array[$var2]}/" "${filename}" + ##echo ${filename} + done + sed -i '' "s/${array[$var1]}/${array[$var2]}/" "userContent.css" +done < "scripts/internal_UUIDs.txt" +echo "UUIDs were ${var3}" diff --git a/userContent.css b/userContent.css index f52105e..38d9a10 100644 --- a/userContent.css +++ b/userContent.css @@ -1083,7 +1083,7 @@ url-prefix(https://discovery.addons.mozilla.org) { } /*! Alters the webextension Dark Mode IMPORTANT: change the Internal UUID */ -@-moz-document url-prefix("moz-extension://{174b2d58-b983-4501-ab4b-07e71203cb43}/") { +@-moz-document url-prefix("moz-extension://{174b2d58-b983-4501-ab4b-07e71203cb43}") { .comment { color: var(--in-content-link-color)!important } @@ -2684,4 +2684,4 @@ url-prefix("moz-extension://{e4a8a97b-f2ed-450b-b12d-ee082ba24781}/src/content/e .frame-block { background: var(--in-content-box-background)!important } -} \ No newline at end of file +}