Last active
July 7, 2024 20:37
-
-
Save natzir/42e66488a63fe0dd74d94bcf0e0c279c to your computer and use it in GitHub Desktop.
getPercentDiff.js
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
javascript:(function()%7Bjavascript%3A!function()%7Bfunction%20e(e)%7Blet%20l%3De.querySelectorAll(%22tr%22)%2Cn%3Dl%5B1%5D%3Bif(!(n%26%26(n.querySelector(%22%3Anth-child(4)%20%3E%20span%20%3E%20span%20%3E%20span%22)%7C%7Cn.querySelector(%22%3Anth-child(7)%20%3E%20span%20%3E%20span%20%3E%20span%22))))for(let%20a%3D1%3Ba%3Cl.length%3Ba%2B%2B)%7Blet%20r%3Dl%5Ba%5D%3Br.cells%5B1%5D.getAttribute(%22data-numeric-value%22)%3Blet%20i%3Dr.cells%5B2%5D.getAttribute(%22data-numeric-value%22)%2Cc%3Dr.cells%5B3%5D.getAttribute(%22data-numeric-value%22)%3Br.cells%5B4%5D.getAttribute(%22data-numeric-value%22)%3Blet%20s%3Dr.cells%5B5%5D.getAttribute(%22data-numeric-value%22)%2Co%3Dr.cells%5B6%5D.getAttribute(%22data-numeric-value%22)%2Cd%3Di%2Cu%3Ds%2Cp%3Dt(c%2Cd)%2Ch%3Dt(o%2Cu)%2Cf%3Dr.querySelector(%22%3Anth-child(4)%20%3E%20span%20%3E%20span%22)%2Cm%3Dr.querySelector(%22%3Anth-child(7)%20%3E%20span%20%3E%20span%22)%2Cg%3Ddocument.createElement(%22span%22)%2C%24%3Ddocument.createElement(%22span%22)%3Bg.innerText%3D%60%20(%24%7Bp%7D)%60%2C%24.innerText%3D%60%20(%24%7Bh%7D)%60%2CisNaN(parseFloat(p))%26%26%22%2B%E2%88%9E%25%22!%3D%3Dp%7C%7C(g.style.color%3Dp.startsWith(%22-%22)%3F%22red%22%3A%22green%22)%2CisNaN(parseFloat(h))%26%26%22%2B%E2%88%9E%25%22!%3D%3Dh%7C%7C(%24.style.color%3Dh.startsWith(%22-%22)%3F%22red%22%3A%22green%22)%2Cf.appendChild(g)%2Cm.appendChild(%24)%7D%7Dfunction%20t(e%2Ct)%7Breturn%200%3D%3D%3Dt%7C%7C%220%22%3D%3D%3Dt%3F%22%2B%E2%88%9E%25%22%3A0%3D%3D%3De%7C%7C%220%22%3D%3D%3De%3F%22-%22%3A(e%2Ft*100).toFixed(2)%2B%22%25%22%7Dconsole.log(%22%5BSC%20Calculator%20by%20Natzir%20Turrado%20%2F%20%40natzir9%5D%22)%2C!function%20e()%7Blet%20t%3D%5B%22scorecard_0%22%2C%22scorecard_1%22%2C%22scorecard_2%22%2C%22scorecard_3%22%5D%2Cl%3D%5B%22Clicks%20Difference%22%2C%22Impressions%20Difference%22%2C%22CTR%20Difference%22%2C%22Position%20Difference%22%5D%3Bfor(let%20n%3D0%3Bn%3Ct.length%3Bn%2B%2B)%7Blet%20a%3Ddocument.evaluate(%60%2F%2Fdiv%5B%40data-guidedhelpid%3D%22%24%7Bt%5Bn%5D%7D%22%5D%2F%2Fdiv%5B%40class%3D%22m10vVd%22%5D%2F%2Fspan%5B%40class%3D%22nnLLaf%20CJvxcd%22%5D%2F%40title%60%2Cdocument%2Cnull%2CXPathResult.ORDERED_NODE_SNAPSHOT_TYPE%2Cnull)%3Bif(a.snapshotLength%3E%3D2)%7Blet%20r%3Da.snapshotLength-2%2Ci%3Da.snapshotLength-1%2Cc%2Cs%3B%22CTR%20Difference%22%3D%3D%3Dl%5Bn%5D%7C%7C%22Position%20Difference%22%3D%3D%3Dl%5Bn%5D%3F(c%3DparseFloat(a.snapshotItem(r).nodeValue.replace(%22%2C%22%2C%22.%22))%2Cs%3DparseFloat(a.snapshotItem(i).nodeValue.replace(%22%2C%22%2C%22.%22)))%3A(c%3DparseFloat(a.snapshotItem(r).nodeValue.replace(%2F%5B%5Cs%2C.%5D%2Fg%2C%22%22))%2Cs%3DparseFloat(a.snapshotItem(i).nodeValue.replace(%2F%5B%5Cs%2C.%5D%2Fg%2C%22%22)))%3Blet%20o%2Cd%3B%22Position%20Difference%22%3D%3D%3Dl%5Bn%5D%3F(o%3D(s-c).toFixed(2)%2Cd%3D((s-c)%2Fs*100).toFixed(2)%2B%22%20%25%22)%3A%22CTR%20Difference%22%3D%3D%3Dl%5Bn%5D%3F(o%3D(c-s).toFixed(2)%2B%22%20%25%22%2Cd%3D((c-s)%2Fs*100).toFixed(2)%2B%22%20%25%22)%3A(d%3D((o%3Dc-s)%2Fs*100).toFixed(2)%2B%22%20%25%22%2Co%3Do.toLocaleString())%3Blet%20u%3Ddocument.createElement(%22div%22)%3Bu.className%3D%22m10vVd%22%3Blet%20p%3Ddocument.createElement(%22div%22)%3Bp.className%3D%22kZiHV%22%3Blet%20h%3Ddocument.createElement(%22span%22)%3Bh.className%3D%22nnLLaf%20CJvxcd%22%2Ch.innerText%3D%60%24%7Bo%7D%5Cn(%24%7Bd%7D)%60%2Ch.style.color%3D0%3EparseFloat(d)%3F%22rgb(205%2036%200)%22%3A%22rgb(78%2C%20225%2C%2078)%22%2Cp.appendChild(h)%2Cu.appendChild(p)%3Blet%20f%3Ddocument.querySelectorAll(%60div%5Bdata-guidedhelpid%3D%22%24%7Bt%5Bn%5D%7D%22%5D%20div.m10vVd%60)%2Cm%3Df%5Bf.length-1%5D%3Bif(m)%7Blet%20g%3Dm.querySelectorAll(%22div.zhJ3J%22)%2C%24%3DArray.from(g).some(e%3D%3Ee.textContent.includes(l%5Bn%5D))%3Bif(%24)continue%3Bm.insertAdjacentElement(%22afterend%22%2Cu)%7D%7D%7D%7D()%2Cfunction%20t()%7Blet%20l%3Ddocument.evaluate(%22%2F%2Ftable%5B%40class%3D'i3WFpf'%5D%22%2Cdocument%2Cnull%2CXPathResult.ORDERED_NODE_SNAPSHOT_TYPE%2Cnull)%3Bfor(let%20n%3D0%3Bn%3Cl.snapshotLength%3Bn%2B%2B)%7Blet%20a%3Dl.snapshotItem(n)%2Cr%3Da.querySelector(%22tr%20%3E%20%3Anth-child(2)%22)%3Br%26%26r.querySelector(%22br%22)%26%26e(a)%7D%7D()%7D()%7D)() |
Do you have a video or instructions on how to get it working? I've installed it in Chrome, but nada
Do you have a video or instructions on how to get it working? I've installed it in Chrome, but nada
It's a bookmarklet that you have to click when you compare two time periods in Search Console.
Thanks @natzir, works really good! 🦾
For those who see this but are confused... in Chrome, go to your Bookmarks Manager, click the three-dot menu, choose Add Bookmark. Copy and paste the code in there. When you're on a GSC page with a comparison, click the bookmark you added. And... thank you, @natzir !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See the percentage difference in your search metrics compared to previous periods. Analyze clicks & impressions across all performance report tabs including Queries, Pages, Countries, Devices, and Search Appearance.