Giter Club home page Giter Club logo

gtvmonkey-scripts's Introduction

Grease/Tamper/Violent-Monkey scripts with KotlinJs

This a template project that helps you write Greasemonkey/Tampermonkey/ViolentMonkey scripts with KotlinJs

Show some โค๏ธ and star the repo to support the project

GitHub stars GitHub forks Twitter Follow

How does it work?

Gradle

I configured a Gradle task buildUserScript that will generate a userscript file. The task will concat the script metadata from main/resources/metadata.txt, the kotlin.js and your generated javascript file. Then it will append main(); to the script, which will execute the main() of your Kotlin Code.

The script will be outputed to /build/distributions/$NAMEOFYOURGRADLEPROJECT.user.js

The gradle task will be triggered after every Gradle build task

Metadata

You can configure the metadata of your userscript inside /src/main/resources/metadata.txt

Kotlin

Write your Kotlin Code inside src/main/kotlin. The main() will be executed first by the userscript.

Hot Reload

When you use gradle -t build inside your project folder, Gradle will detect all changes to your Kotlin Code and metadata.txt file, and will compile and generate a new userscript on every change. The detection of changes on the userscript depends on your used addon. E.g. Violentmonkey supports tracking of file changes in Chrome (https://violentmonkey.github.io/posts/how-to-edit-scripts-with-your-favorite-editor/) and it can detect changes on a new generated userscript.

Example

Let's create a script thats alerts "Hello GitHub" on every page of GitHub.

Add this inside your /main/resources/metadata.txt

// ==UserScript==
// @name        MyNew script - KotlinJs
// @namespace   GtvMonkey Scripts
// @grant       none
// @version     1.0
// @author      -
// @description 10/16/2020, 9:43:07 PM
// @include     https://github.com/*
// ==/UserScript==

You can find out more about the Metadata section HERE

This is your Kotlin Code

fun main() {
    window.alert("Hello Github!")
}

Run the build task of Gradle and you will find a *.user.js inside /build/distributions. Add this file to your wanted userscript browser addon and you are done.

๐Ÿ“œ License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE.md file for details


Copyright 2020 Jens Klingenberg

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

gtvmonkey-scripts's People

Contributors

foso avatar jensklingenbergedeka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gtvmonkey-scripts's Issues

Adding kotlinx-coroutines-core as a dependency

Thanks for the template, very helpful.
I added these 2 lines to the Gradle dependencies block:

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.4.3'

and changed the main function to:

suspend fun main() {
    val response = window.fetch("https://github.com/", RequestInit(method = "GET")).await()
}

Then executed the build task, which completed successfully. But when the script tries to run, I get:
Error: Error loading module 'gtvmonkey'. Its dependency 'kotlinx-coroutines-core' was not found. Please, check whether 'kotlinx-coroutines-core' is loaded prior to 'gtvmonkey'.

How do I fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.