Git Product home page Git Product logo

Comments (6)

suttas avatar suttas commented on June 12, 2024 1

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.

thesunshade avatar thesunshade commented on June 12, 2024

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.

suttas avatar suttas commented on June 12, 2024

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.

thesunshade avatar thesunshade commented on June 12, 2024

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.

suttas avatar suttas commented on June 12, 2024

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.

sujato avatar sujato commented on June 12, 2024

Thanks to both for this discussion, I agree with the points raised and will discuss the implementation with Hongda.

from suttacentral.

Related Issues (20)

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.