ramajs

web browser automation from your browser console
git clone https://tongong.net/git/ramajs.git
Log | Files | Refs | README | LICENSE

commit c5cba38b08d4c5ee12cf4fe796014d2262dcb08b
parent df5d92f51caec3eb20ce21508576d12677f91de5
Author: tongong <tongong@gmx.net>
Date:   Fri, 27 Nov 2020 21:52:27 +0100

added rframe object handling

Diffstat:
MREADME.md | 15++++++++++-----
Mrama.js | 31++++++++++++++++++++++++++++++-
2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md @@ -1,7 +1,5 @@ # rama.js -# AT THE MOMENT ONLY AN IDEA AND NO ACTUAL IMPLEMENTATION EXISTS - ## about The simplest way to automate web tasks is using the language of the web - Javascript and the normal web apis by just running the code from the developer console. This way you don't need to install any program, extension or separate browser to just automate this one feature. Additionally you don't need to learn any new tools or apis. @@ -41,11 +39,11 @@ let client = rama.new({ }); ``` -#### rframe.close() -Removes the iframe from the DOM. +#### rframe.t or rframe.tag (read-only) +Access the `<iframe>`-tag. ```javascript -client.close(); +client.t.classList.add("invisible"); ``` #### rframe.d or rframe.document (read-only) @@ -99,6 +97,13 @@ await client.waitForSelector("#some-div-somewhere"); // do something on the new page ``` +#### rframe.close() +Removes the iframe from the DOM. + +```javascript +client.close(); +``` + #### rama.clearpage() Clears the current window by setting the `<body>` to `display: none`. Changes the standard parent for new iframes to the `<html>`-tag to keep them visible. diff --git a/rama.js b/rama.js @@ -28,6 +28,35 @@ rama = { iframeTag.id = config.name; iframeTag.classList.add("rama-frame"); config.parent.appendChild(iframeTag); + + // create the rframe object + // is this the correct way to create an object? it works... + const rframe = { + tag: iframeTag, + t: iframeTag, + // d & document are added when the page loads (see below) + w: iframeTag.contentWindow, + window: iframeTag.contentWindow, + name: config.name, + id: config.name, + + waitForReload: function () {}, + waitForUpdate: function () {}, + waitForSelector: function () {}, + close: function () { + this.tag.parentElement.removeChild(this.tag); + } + }; + // add events for the .document attribute (changes at reload) + iframeTag.addEventListener("load", () => { + rframe.document = iframeTag.contentDocument; + // qsa() function + rframe.document.qsa = function (selector) { + return Array.from(rframe.document.querySelectorAll(selector)); + }; + rframe.d = rframe.document; + }); + return rframe; }, clearpage: function () { @@ -35,7 +64,7 @@ rama = { // but it enables us in this case to completely switch to the iframe window this.stdparent = document.querySelector("html"); this.loadcss( - ".rama-frame { width: 100vw; height: 100vh; postion: fixed; top: 0; left: 0; } " + + ".rama-frame { width: 100vw; height: 100vh; position: fixed; top: 0; left: 0; } " + "body { display: none; } " + "html { overflow: hidden; } " );