I created the following Chrome bookmarklet to open all elements with text Extra Examples boxes on this page. For example - the element labeled with text Extra Examples below can be clicked:
When it is clicked then a list of examples will be displayed:
The element can then be clicked again to hide the list of examples.
The bookmarklet code
javascript:$('.box_title').click();
It works with no problem. However, I'd prefer to use vanilla JavaScript. This is what I have for now:
javascript:document.querySelectorAll('.box_title').forEach(e => e.click());
Do you see any problem, or can it be improved?
Demonstration
Below is a runnable snippet that shows a sample of the page without the bookmarklet:
<link href="https://www.oxfordlearnersdictionaries.com/external/styles/oald10.css" rel="stylesheet" />
<link href="https://www.oxfordlearnersdictionaries.com/external/styles/interface.css" rel="stylesheet" />
<span class="shcut-g" id="get_sngs_2"> <h2 class="shcut" htag="h2" id="get_shcut_2" hclass="shcut">bring</h2><li class="sense" cefr="a1" id="get_sng_4" hclass="sense" htag="li" sensenum="5" ox3000="y"><a class="open oup_icons" title="Add to My Word Lists"><span class="star-btn" aria-hidden="true"></span></a>
<span
class="sensetop" hclass="sensetop" htag="span">
<div class="symbols" htag="div" hclass="symbols"><a href="https://www.oxfordlearnersdictionaries.com/wordlists/oxford3000-5000?dataset=english&list=ox3000&level=a1"><span class="ox3ksym_a1"> </span></a></div>
</span> <span class="grammar" hclass="grammar" htag="span">[transitive]</span> <span class="def" htag="span" hclass="def">to go to a place and bring somebody/something back</span> <span class="xrefs" htag="span" xt="nsyn" hclass="xrefs"><span class="prefix">synonym</span> <a class="Ref" href="https://www.oxfordlearnersdictionaries.com/definition/english/fetch" title="fetch definition"><span class="xr-g" href="fetch_e" bord="n"><span class="xh">fetch</span></span></a></span>
<ul class="examples" hclass="examples" htag="ul">
<li class="" htag="li"> <span class="cf" htag="span" hclass="cf">get somebody/something</span> <span class="x">Quick—<span class="cl">go and get</span> a cloth!</span>
</li>
<li class="" htag="li"><span class="x">Somebody get a doctor!</span></li>
<li class="" htag="li"><span class="x">She went to <span class="cl">get help</span>.</span>
</li>
<li class="" htag="li"><span class="x">I have to go and get my mother from the airport <span class="gloss" htag="span" hclass="gloss">(= collect her)</span>.</span>
</li>
<li class="" htag="li"> <span class="cf" hclass="cf" htag="span">get something for somebody</span> <span class="x">Get a drink for John.</span></li>
<li class="" htag="li"> <span class="cf" htag="span" hclass="cf">get somebody/yourself something</span> <span class="x">Get John a drink.</span></li>
</ul>
<div class="collapse" htag="div" hclass="collapse"><span class="unbox" id="get_unbox_2" unbox="extra_examples"><span class="box_title">Extra Examples</span>
<ul class="examples" hclass="examples" htag="ul">
<li class="" htag="li"><span class="unx">She's gone to get a few more chairs.</span></li>
<li class="" htag="li"><span class="unx">Could you go upstairs and get my wallet for me, please?</span></li>
<li class="" htag="li"><span class="unx">Can I get you anything to eat or drink?</span></li>
</ul>
</span>
</div>
</li>
</span>
<div id="flex-menu"></div>
<div id="panel-smartphone"></div>
<div id="dictionarySelector"></div>
<script src="https://www.oxfordlearnersdictionaries.com/common.js"></script>
<script src="https://www.oxfordlearnersdictionaries.com/external/scripts/jquery.lightbox-0.5.min.js"></script>
<script src="https://www.oxfordlearnersdictionaries.com/external/scripts/oxford.js"></script>
<script src="https://www.oxfordlearnersdictionaries.com/external/scripts/entry.js"></script>
<script language="javascript" type="text/javascript">
var contextId= (location.hash != "" ? location.hash : null);
// global variable that contains the path to external files
// and used by the lightbox script
var lightboxImageLoading = "https://www.oxfordlearnersdictionaries.com/external/images/lightbox-ico-loading.gif?version=2.3.41";
var lightboxImageBtnPrev = "https://www.oxfordlearnersdictionaries.com/external/images/lightbox-btn-prev.gif?version=2.3.41";
var lightboxImageBtnNext = "https://www.oxfordlearnersdictionaries.com/external/images/lightbox-btn-next.gif?version=2.3.41";
var lightboxImageBtnClose = "https://www.oxfordlearnersdictionaries.com/external/images/lightbox-btn-close.gif?version=2.3.41";
var lightboxImageBlank = "https://www.oxfordlearnersdictionaries.com/external/images/lightbox-blank.gif?version=2.3.41";
if (document.readyState != 'loading'){
initEntry('See more', 'See less');
} else if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', function(){initEntry('See more', 'See less');});
} else {
document.attachEvent('onreadystatechange', function() {
if (document.readyState != 'loading')
initEntry('See more', 'See less');
});
}
</script>
And here is the code with the effect of the bookmarklet added:
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.box_title').forEach(e => e.click());
});
<link href="https://www.oxfordlearnersdictionaries.com/external/styles/oald10.css" rel="stylesheet" />
<link href="https://www.oxfordlearnersdictionaries.com/external/styles/interface.css" rel="stylesheet" />
<span class="shcut-g" id="get_sngs_2"> <h2 class="shcut" htag="h2" id="get_shcut_2" hclass="shcut">bring</h2><li class="sense" cefr="a1" id="get_sng_4" hclass="sense" htag="li" sensenum="5" ox3000="y"><a class="open oup_icons" title="Add to My Word Lists"><span class="star-btn" aria-hidden="true"></span></a>
<span
class="sensetop" hclass="sensetop" htag="span">
<div class="symbols" htag="div" hclass="symbols"><a href="https://www.oxfordlearnersdictionaries.com/wordlists/oxford3000-5000?dataset=english&list=ox3000&level=a1"><span class="ox3ksym_a1"> </span></a></div>
</span> <span class="grammar" hclass="grammar" htag="span">[transitive]</span> <span class="def" htag="span" hclass="def">to go to a place and bring somebody/something back</span> <span class="xrefs" htag="span" xt="nsyn" hclass="xrefs"><span class="prefix">synonym</span> <a class="Ref" href="https://www.oxfordlearnersdictionaries.com/definition/english/fetch" title="fetch definition"><span class="xr-g" href="fetch_e" bord="n"><span class="xh">fetch</span></span></a></span>
<ul class="examples" hclass="examples" htag="ul">
<li class="" htag="li"> <span class="cf" htag="span" hclass="cf">get somebody/something</span> <span class="x">Quick—<span class="cl">go and get</span> a cloth!</span>
</li>
<li class="" htag="li"><span class="x">Somebody get a doctor!</span></li>
<li class="" htag="li"><span class="x">She went to <span class="cl">get help</span>.</span>
</li>
<li class="" htag="li"><span class="x">I have to go and get my mother from the airport <span class="gloss" htag="span" hclass="gloss">(= collect her)</span>.</span>
</li>
<li class="" htag="li"> <span class="cf" hclass="cf" htag="span">get something for somebody</span> <span class="x">Get a drink for John.</span></li>
<li class="" htag="li"> <span class="cf" htag="span" hclass="cf">get somebody/yourself something</span> <span class="x">Get John a drink.</span></li>
</ul>
<div class="collapse" htag="div" hclass="collapse"><span class="unbox" id="get_unbox_2" unbox="extra_examples"><span class="box_title">Extra Examples</span>
<ul class="examples" hclass="examples" htag="ul">
<li class="" htag="li"><span class="unx">She's gone to get a few more chairs.</span></li>
<li class="" htag="li"><span class="unx">Could you go upstairs and get my wallet for me, please?</span></li>
<li class="" htag="li"><span class="unx">Can I get you anything to eat or drink?</span></li>
</ul>
</span>
</div>
</li>
</span>
<div id="flex-menu"></div>
<div id="panel-smartphone"></div>
<div id="dictionarySelector"></div>
<script src="https://www.oxfordlearnersdictionaries.com/common.js"></script>
<script src="https://www.oxfordlearnersdictionaries.com/external/scripts/jquery.lightbox-0.5.min.js"></script>
<script src="https://www.oxfordlearnersdictionaries.com/external/scripts/oxford.js"></script>
<script src="https://www.oxfordlearnersdictionaries.com/external/scripts/entry.js"></script>
<script language="javascript" type="text/javascript">
var contextId= (location.hash != "" ? location.hash : null);
// global variable that contains the path to external files
// and used by the lightbox script
var lightboxImageLoading = "https://www.oxfordlearnersdictionaries.com/external/images/lightbox-ico-loading.gif?version=2.3.41";
var lightboxImageBtnPrev = "https://www.oxfordlearnersdictionaries.com/external/images/lightbox-btn-prev.gif?version=2.3.41";
var lightboxImageBtnNext = "https://www.oxfordlearnersdictionaries.com/external/images/lightbox-btn-next.gif?version=2.3.41";
var lightboxImageBtnClose = "https://www.oxfordlearnersdictionaries.com/external/images/lightbox-btn-close.gif?version=2.3.41";
var lightboxImageBlank = "https://www.oxfordlearnersdictionaries.com/external/images/lightbox-blank.gif?version=2.3.41";
if (document.readyState != 'loading'){
initEntry('See more', 'See less');
} else if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', function(){initEntry('See more', 'See less');});
} else {
document.attachEvent('onreadystatechange', function() {
if (document.readyState != 'loading')
initEntry('See more', 'See less');
});
}
</script>
P.S. This is where everything started: "Expand all comments" button. A jQuery snippet is already suggested, but I prefer a plain JavaScript solution as jQuery isn't always available, e.g., on this dictionary.