Last active
March 21, 2023 13:35
-
-
Save dashtaki/0b437b2ac7c0331c86f90408b681243a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Coda-RTL | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description right to left coda.io documents! | |
// @author You | |
// @match https://coda.io/d/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var docName, urlPath, currentHash, domLoadedInterval; | |
setTimeout(function(){ | |
console.log("tampermonkey Actived :-)"); | |
var urlPath = location.pathname.replace("/d/",""); | |
var docName = urlPath.substring(0, urlPath.indexOf("_")); | |
var currentHash = location.hash; | |
if(docName == ""){ | |
console.log("page is RTL"); | |
addNewStyles(); | |
domLoadedInterval = setInterval(function(){ | |
init(); | |
}, 1000); | |
var hashChangeInterval = setInterval(function(){ | |
var urlPath = location.pathname; | |
var sectionName = urlPath.substring(urlPath.lastIndexOf("/") +1, urlPath.lastIndexOf("_")); | |
if(location.hash != currentHash){ | |
init(); | |
console.log("section changed"); | |
currentHash = location.hash; | |
} | |
},1000); | |
} | |
else{ | |
console.log("page is LTR"); | |
} | |
} ,3000); | |
function init(){ | |
var rootElement = document.getElementsByClassName("editable--root--m-Hp5xET")[0]; | |
if(rootElement) | |
{ | |
rootElement.setAttribute("dir", "rtl"); | |
console.log("root element direction changed to RTL!"); | |
clearInterval(domLoadedInterval); | |
} | |
} | |
function addNewStyles(){ | |
var styleElement = document.createElement("style"); | |
styleElement.type= "text/css"; | |
var sidebar = '.Js6D48p4{ left: auto; right: 0; }' | |
var content = '.kr-document-root .kr-canvas-section-viewport{margin-left: initial; margin-right: 280px;}' | |
var table = '.HVtqADz6{ direction: rtl; }' | |
var paragrapg = '.HVtqADz6 > * { text-align: right; }' | |
var header = 'header { margin-left: initial !important ; margin-right: 285px !important; } header .jpSfAoNy { flex-direction: row-reverse; }' | |
var topIconsContainer = 'header .jpSfAoNy div:nth-child(2) { flex-direction: row-reverse; }' | |
var userIcon = 'header .jpSfAoNy div:nth-child(2) div[data-is-transparent-container]:last-child span { padding-left: 0; }' | |
var gearIcon = 'header .jpSfAoNy div:nth-child(2) span[data-coda-logging-id="settings"] { margin-left: 10px; }' | |
var commentBox = 'div[data-coda-ui-id="commentRail"]{ position: absolute; right: initial; height: 100%; } div[data-coda-ui-id="commentRail"]:hover{ border-left: 0; border-right: 1px solid rgb(224, 224, 224);}' | |
var commentArrowIcon = 'div[data-coda-ui-id="commentRail"] .icon{ transform: rotateY(180deg); }' | |
var pageOptionContainer = '.I_GqfUwz{ flex-direction: row-reverse; }' | |
var styleText = document.createTextNode(sidebar + content + table + paragrapg + header + commentBox + commentArrowIcon + pageOptionContainer + topIconsContainer + userIcon + gearIcon); | |
styleElement.appendChild(styleText); | |
var head = document.getElementsByTagName("head")[0]; | |
head.appendChild(styleElement); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can just install TamperMonkey extension and follow the instruction.
@CyRamos