Comments (6)
Honestly I have no idea how this could be done outside completely restructuring the DOM. One thing that seems to work is disabling
user-select
when a key is pressed. For example:
That's great!
I got another suggestion below.
First, here's a little improvement that also hides the comments. Changed the button to Control because I end up Ctrl+C after selecting anyway.
// ==UserScript==
// @name block selecting
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://suttacentral.net/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=suttacentral.net
// @grant none
// ==/UserScript==
(function() {
'use strict';
const roots=document.getElementsByClassName("root")
const comments=document.getElementsByClassName("comment")
document.onkeydown=(e)=>{
if (e.key=="Control"){
for (let i=0;i<roots.length;i++){
roots[i].style.userSelect="none"
roots[i].style.color="rgb(211, 209, 208)"
comments[i].style.display="none"
}
}
}
document.onkeyup=(e)=>{
if (e.key=="Control"){
for (let i=0;i<roots.length;i++){
roots[i].style.userSelect="inherit"
roots[i].style.color="inherit"
comments[i].style.display="inline-block"
}
}
}
})();
But wouldn't it somehow be possible to:
- start the script with a document.onselectstart or mousedown,
- retrieve the class of the clicked element (root or translation),
- or otherwise the mouse position inside the window (calculating whether it's in the left or right half),
- and use it to toggle the userSelect of respectively the root or the translation
- (and if needed toggle userSelect back on when mouseup)
Then it would do pretty much exactly what we'd want.
If somebody can get this to work (sorry my JS is too rusty), then it should also not select the alternative manuscript readings, the purple *'s. They should hide as the comments do.
from suttacentral.
Honestly I have no idea how this could be done outside completely restructuring the DOM. One thing that seems to work is disabling user-select
when a key is pressed. For example:
// ==UserScript==
// @name block selecting
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://suttacentral.net/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=suttacentral.net
// @grant none
// ==/UserScript==
(function() {
'use strict';
const roots=document.getElementsByClassName("root")
document.onkeydown=(e)=>{
if (e.key=="Alt"){
for (let i=0;i<roots.length;i++){
roots[i].style.userSelect="none"
roots[i].style.color="rgb(211, 209, 208)"
}
}
}
document.onkeyup=(e)=>{
if (e.key=="Alt"){
for (let i=0;i<roots.length;i++){
roots[i].style.userSelect="inherit"
roots[i].style.color="inherit"
}
}
}
})();
from suttacentral.
What should happen (somehow or other) is that only the English would get selected:
Ideally what happens is that only the language you start selecting gets selected, just as if the two languages were two columns in a table. If you start selecting Pali, it doesn't switch to selecting English, and vice-versa.
I have no idea on how to do this, unfortunately. But perhaps this may be used:
https://stackoverflow.com/questions/43272295/alter-the-order-of-text-selection-across-elements
Comments should'nt be selected
Another related issue is that the content of the comments gets copied along the main text, even if you haven't opened the comment by mouseover. It should just select the main text.
from suttacentral.
Have you tested this? I don't think
comments[i].style.display="none"
will work since the number of nodes in comments
is different from the number of nodes in roots
.
And was there a reason you did display="none"
? instead of userSelect="none"
?
I didn't know about onselectstart
. I tried onmousedown
but I ran into some problems because it's easy to start the selection outside of the actual element without knowing. Ans when you do manage to select the root text, the element was class word
and not root
. So basically lots of fussy things.
In any case, I doubt if Bhante is interested in a solution in the website itself that involves js.
BTW, I had used Alt since it is often associated with vertical text selection.
from suttacentral.
There's always more nodes in roots than comments, so it does work, but I can see how it can be optimized if needed. Just trying to get the desired behavior first.
I do think onselecstart will work in combination with calculating the mouse position. Anyway, if such a JS solution is not desired for the site, then it may not be worth the effort.
from suttacentral.
Thanks to both for this discussion, I agree with the points raised and will discuss the implementation with Hongda.
from suttacentral.
Related Issues (20)
- Redesign SERP and instant search input box to match latest Material Design HOT 5
- Document Language list does not update on SERP when settings change HOT 3
- Add a search button to the input field on SERP HOT 4
- `volpage:` search is returning lots of wrong and unnecessary results HOT 3
- Instant search should be prioritizing actual matches over typo suggestions HOT 1
- Texts without any subheadings are sometimes getting TOC buttons and empty overlays HOT 1
- Filter (collection) parameters must be able to include dashes HOT 1
- Only return one translation of any given text with preference to segmented texts HOT 1
- Double blank dictionary results are returned for `uppādetv` match partial HOT 5
- Currency drop down on form on donate-now page drops up and hides behind header HOT 3
- provide option for other site search, eg. DuckDuckGo?
- make UI for using Dictionaries more directly?
- pull in results from CPD? (http://pali.hum.ku.dk/cpd/search.html)
- During build, duplicate key error for Geiger SN1 and SN2 HOT 12
- Make the search urls more human readable by substituting spaces with `+` signs
- Incorrect "You're offline" message for invalid URLs HOT 1
- In the Algolia search, operators should not be searched as keywords
- Highlighted Pali search keywords are missing diacritics on the full database search result page HOT 6
- If no document languages are selected, then explicitly search in all documents HOT 3
- If there are no search results on SERP, check to see if user's site language and search document language match HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from suttacentral.