Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
7dJx1qP committed Sep 10, 2022
0 parents commit 568ec6f
Show file tree
Hide file tree
Showing 12 changed files with 1,044 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/local
__pycache__
stashdb-userscripts.code-workspace
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# StashDB Userscripts

## [INSTALL USERSCRIPT](dist/public/StashDB%20Userscripts%20Bundle.user.js?raw=1)

Installation requires a browser extension such as [Violentmonkey](https://violentmonkey.github.io/) / [Tampermonkey](https://www.tampermonkey.net/) / [Greasemonkey](https://www.greasespot.net/).

> You may remove any unwanted userscripts from the bundle by removing the line that starts with `// @require` that corresponds to the userscript you wish to remove.
![Allow cors - Tamper Monkey](images/allow-cors-tamper-monkey.png?raw=true "Allow cors - Tamper Monkey")

## Developing

Each userscript source is split into two files:
* `src/header` - Folder with userscript metadata blocks
* `src/body` - Folder with main script code

Execute `py build.py` to combine source files and generate:
* a userscript bundle to `dist\local` for local development
* individual userscripts and a bundle to `dist\public` for release

Build output directories:
* `dist\local` - A userscript bundle with `@require` headers that load the script code from local files (`src/body`)
* `dist\public` - Userscripts with `@require` headers that load the script code from this github repo
106 changes: 106 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import os
import config
import shutil
from pathlib import Path

def get_active_branch_name():
head_dir = Path(".") / ".git" / "HEAD"
with head_dir.open("r") as f: content = f.read().splitlines()

for line in content:
if line[0:4] == "ref:":
return line.partition("refs/heads/")[2]

def build():
ROOTDIR = Path(__file__).parent.resolve()
LIBFILE = "StashDBUserscriptLibrary.js"
GIT_BRANCH = get_active_branch_name()
GITHUB_ROOT_URL = config.GITHUB_ROOT_URL.replace('%%BRANCH%%', GIT_BRANCH)
print('git branch', GIT_BRANCH)

localbodyfiles = []
distbodyfiles = []
distlibfile = os.path.join(GITHUB_ROOT_URL, 'src', LIBFILE)
for file in os.listdir('src/header'):
# headerpath = os.path.join('src/header', file)
# bodypath = os.path.join('src/body', file)
# distpublicpath = os.path.join('dist/public', file)
# header = open(headerpath, 'r').read()
# body = open(bodypath, 'r').read()

localbodyfiles.append("file://" + os.path.join(ROOTDIR, 'src/body', file))
distbodyfiles.append(os.path.join(GITHUB_ROOT_URL, 'src/body', file))

# header = header.replace("%NAMESPACE%", config.NAMESPACE) \
# .replace("%LIBRARYPATH%", distlibfile) \
# .replace("%MATCHURL%", f"{config.SERVER_URL}/*") \
# .replace("// @require %FILEPATH%\n", "")
# distscript = header + "\n\n" + body
# with open(distpublicpath, 'w') as f:
# f.write(distscript)
# print(distpublicpath)

localpath = 'dist/local/StashDB Userscripts Development Bundle.user.js'
locallibfile = "file://" + os.path.join(ROOTDIR, 'src', LIBFILE)
with open(localpath, 'w') as f:
f.write(f"""// ==UserScript==
// @name StashDB Userscripts Development Bundle
// @namespace {config.NAMESPACE}
// @description StashDB Userscripts Development Bundle
// @version {config.BUNDLE_VERSION}
// @author 7dJx1qP
// @match {config.SERVER_URL}/*
// @resource IMPORTED_CSS file://{os.path.join(ROOTDIR, 'src')}\scene.css
// @grant unsafeWindow
// @grant GM_setClipboard
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM.getValue
// @grant GM.setValue
// @grant GM.listValues
// @grant GM.xmlHttpRequest
// @connect localhost
// @require {locallibfile}
//
// **************************************************************************************************
// * YOU MAY REMOVE ANY OF THE @require LINES BELOW FOR SCRIPTS YOU DO NOT WANT *
// **************************************************************************************************
//\n""")
for localbodyfile in localbodyfiles:
f.write(f"// @require {localbodyfile}\n")
f.write("\n// ==/UserScript==\n")
print(localpath)

distpath = 'dist/public/StashDB Userscripts Bundle.user.js'
with open(distpath, 'w') as f:
f.write(f"""// ==UserScript==
// @name StashDB Userscripts Bundle
// @namespace {config.NAMESPACE}
// @description StashDB Userscripts Bundle
// @version {config.BUNDLE_VERSION}
// @author 7dJx1qP
// @match {config.SERVER_URL}/*
// @resource IMPORTED_CSS https://raw.githubusercontent.com/7dJx1qP/stashdb-userscripts/{GIT_BRANCH}/dist/public/scene.css
// @grant unsafeWindow
// @grant GM_setClipboard
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM.getValue
// @grant GM.setValue
// @grant GM.listValues
// @grant GM.xmlHttpRequest
// @connect localhost
// @require {distlibfile}
//
// **************************************************************************************************
// * YOU MAY REMOVE ANY OF THE @require LINES BELOW FOR SCRIPTS YOU DO NOT WANT *
// **************************************************************************************************
//\n""")
for distbodyfile in distbodyfiles:
f.write(f"// @require {distbodyfile}\n")
f.write("\n// ==/UserScript==\n")
print(distpath)

shutil.copyfile('src/scene.css', 'dist/public/scene.css')

build()
4 changes: 4 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GITHUB_ROOT_URL = r"https://raw.githubusercontent.com/7dJx1qP/stashdb-userscripts/%%BRANCH%%/"
BUNDLE_VERSION = "0.1.1"
SERVER_URL = "https://stashdb.org"
NAMESPACE = "https://github.com/7dJx1qP/stashdb-userscripts"
26 changes: 26 additions & 0 deletions dist/public/StashDB Userscripts Bundle.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// ==UserScript==
// @name StashDB Userscripts Bundle
// @namespace https://github.com/7dJx1qP/stashdb-userscripts
// @description StashDB Userscripts Bundle
// @version 0.1.1
// @author 7dJx1qP
// @match https://stashdb.org/*
// @resource IMPORTED_CSS https://raw.githubusercontent.com/7dJx1qP/stashdb-userscripts/master/dist/public/scene.css
// @grant unsafeWindow
// @grant GM_setClipboard
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM.getValue
// @grant GM.setValue
// @grant GM.listValues
// @grant GM.xmlHttpRequest
// @connect localhost
// @require https://raw.githubusercontent.com/7dJx1qP/stashdb-userscripts/master/src\StashDBUserscriptLibrary.js
//
// **************************************************************************************************
// * YOU MAY REMOVE ANY OF THE @require LINES BELOW FOR SCRIPTS YOU DO NOT WANT *
// **************************************************************************************************
//
// @require https://raw.githubusercontent.com/7dJx1qP/stashdb-userscripts/master/src/body\StashDB Copy StashID.user.js

// ==/UserScript==
73 changes: 73 additions & 0 deletions dist/public/scene.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
.stash_id_match a:hover {
background-color: rgba(0, 0, 0, 0.541);
color: #fff !important;
}

.stash_id_match.search_match {
position: absolute;
top: 10px;
right: 10px;
align-self: center;
}

.stash_id_match.scene_match {
position: relative;
margin-left: 10px;
cursor: pointer;
align-self: center;
display: inline;
}

.match-yes {
color: green;
}

.match-no {
color: red;
}

.stash_id_ignored .match-no {
color: yellow;
}

.stash_id_wanted .match-no {
color: gold;
}

.stash_id_match svg {
height: 24px;
width: 24px;
}

.stash-performer-link img {
width: 2rem;
padding-left: 0.5rem;
}

.scene-performers .stash-performer-link {
padding-right: 0.25rem;
}

.SearchPage .stash-performer-link img {
width: 2rem;
padding-left: 0rem;
margin-right: 10px;
}

.stash_id_ignored,
.stash_id_ignored > .card {
background-color: rgba(48, 64, 77, 0.25) !important;
}

.stash_id_ignored img {
opacity: 0.25;
}

.settings-box {
padding: 1rem;
margin-bottom: 0;
position: absolute;
right: 0;
z-index: 999;
background-color: inherit;
}
Binary file added images/allow-cors-tamper-monkey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 568ec6f

Please sign in to comment.